2011-12-13 10:21:42 +08:00
|
|
|
|
" ========================================
|
|
|
|
|
" General vim sanity improvements
|
|
|
|
|
" ========================================
|
|
|
|
|
"
|
2012-01-21 10:01:06 +08:00
|
|
|
|
"
|
2011-12-16 14:20:51 +08:00
|
|
|
|
" alias yw to yank the entire word 'yank inner word'
|
|
|
|
|
" even if the cursor is halfway inside the word
|
|
|
|
|
" FIXME: will not properly repeat when you use a dot (tie into repeat.vim)
|
|
|
|
|
nnoremap ,yw yiww
|
|
|
|
|
|
|
|
|
|
" ,ow = 'overwrite word', replace a word with what's in the yank buffer
|
|
|
|
|
" FIXME: will not properly repeat when you use a dot (tie into repeat.vim)
|
2012-01-21 10:43:49 +08:00
|
|
|
|
nnoremap ,ow "_diwhp
|
2011-12-16 14:20:51 +08:00
|
|
|
|
|
2011-12-13 12:42:54 +08:00
|
|
|
|
"make Y consistent with C and D
|
|
|
|
|
nnoremap Y y$
|
2013-06-17 03:10:45 +08:00
|
|
|
|
function! YRRunAfterMaps()
|
|
|
|
|
nnoremap Y :<C-U>YRYankCount 'y$'<CR>
|
|
|
|
|
endfunction
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2014-01-26 02:56:54 +08:00
|
|
|
|
" Make 0 go to the first character rather than the beginning
|
|
|
|
|
" of the line. When we're programming, we're almost always
|
|
|
|
|
" interested in working with text rather than empty space. If
|
|
|
|
|
" you want the traditional beginning of line, use ^
|
|
|
|
|
nnoremap 0 ^
|
|
|
|
|
nnoremap ^ 0
|
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" ========================================
|
|
|
|
|
" RSI Prevention - keyboard remaps
|
|
|
|
|
" ========================================
|
|
|
|
|
" Certain things we do every day as programmers stress
|
2011-12-24 13:05:50 +08:00
|
|
|
|
" out our hands. For example, typing underscores and
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" dashes are very common, and in position that require
|
2011-12-24 13:05:50 +08:00
|
|
|
|
" a lot of hand movement. Vim to the rescue
|
2011-12-13 10:21:42 +08:00
|
|
|
|
"
|
|
|
|
|
" Now using the middle finger of either hand you can type
|
|
|
|
|
" underscores with apple-k or apple-d, and add Shift
|
|
|
|
|
" to type dashes
|
|
|
|
|
imap <silent> <D-k> _
|
|
|
|
|
imap <silent> <D-d> _
|
|
|
|
|
imap <silent> <D-K> -
|
|
|
|
|
imap <silent> <D-D> -
|
2012-01-07 02:33:00 +08:00
|
|
|
|
|
2012-05-08 14:55:41 +08:00
|
|
|
|
" ,# Surround a word with #{ruby interpolation}
|
|
|
|
|
map ,# ysiw#
|
2012-05-10 08:54:30 +08:00
|
|
|
|
vmap ,# c#{<C-R>"}<ESC>
|
|
|
|
|
|
|
|
|
|
" ," Surround a word with "quotes"
|
2012-05-08 14:55:41 +08:00
|
|
|
|
map ," ysiw"
|
2012-05-10 08:54:30 +08:00
|
|
|
|
vmap ," c"<C-R>""<ESC>
|
|
|
|
|
|
|
|
|
|
" ,' Surround a word with 'single quotes'
|
|
|
|
|
map ,' ysiw'
|
|
|
|
|
vmap ,' c'<C-R>"'<ESC>
|
|
|
|
|
|
|
|
|
|
" ,) or ,( Surround a word with (parens)
|
|
|
|
|
" The difference is in whether a space is put in
|
|
|
|
|
map ,( ysiw(
|
|
|
|
|
map ,) ysiw)
|
|
|
|
|
vmap ,( c( <C-R>" )<ESC>
|
|
|
|
|
vmap ,) c(<C-R>")<ESC>
|
|
|
|
|
|
|
|
|
|
" ,[ Surround a word with [brackets]
|
|
|
|
|
map ,] ysiw]
|
|
|
|
|
map ,[ ysiw[
|
|
|
|
|
vmap ,[ c[ <C-R>" ]<ESC>
|
|
|
|
|
vmap ,] c[<C-R>"]<ESC>
|
|
|
|
|
|
|
|
|
|
" ,{ Surround a word with {braces}
|
|
|
|
|
map ,} ysiw}
|
|
|
|
|
map ,{ ysiw{
|
|
|
|
|
vmap ,} c{ <C-R>" }<ESC>
|
|
|
|
|
vmap ,{ c{<C-R>"}<ESC>
|
2012-05-08 14:55:41 +08:00
|
|
|
|
|
2013-08-05 06:58:12 +08:00
|
|
|
|
map ,` ysiw`
|
|
|
|
|
|
2012-04-16 03:31:56 +08:00
|
|
|
|
" gary bernhardt's hashrocket
|
|
|
|
|
imap <c-l> <space>=><space>
|
|
|
|
|
|
2012-05-15 21:43:49 +08:00
|
|
|
|
" Change inside various enclosures with Cmd-" and Cmd-'
|
|
|
|
|
" The f makes it find the enclosure so you don't have
|
|
|
|
|
" to be standing inside it
|
|
|
|
|
nnoremap <D-'> f'ci'
|
|
|
|
|
nnoremap <D-"> f"ci"
|
|
|
|
|
nnoremap <D-(> f(ci(
|
|
|
|
|
nnoremap <D-)> f)ci)
|
|
|
|
|
nnoremap <D-[> f[ci[
|
|
|
|
|
nnoremap <D-]> f]ci]
|
2012-01-21 08:28:39 +08:00
|
|
|
|
|
2011-12-18 05:27:01 +08:00
|
|
|
|
"Go to last edit location with ,.
|
|
|
|
|
nnoremap ,. '.
|
|
|
|
|
|
2012-01-23 10:47:55 +08:00
|
|
|
|
"When typing a string, your quotes auto complete. Move past the quote
|
|
|
|
|
"while still in insert mode by hitting Ctrl-a. Example:
|
|
|
|
|
"
|
|
|
|
|
" type 'foo<c-a>
|
|
|
|
|
"
|
|
|
|
|
" the first quote will autoclose so you'll get 'foo' and hitting <c-a> will
|
|
|
|
|
" put the cursor right after the quote
|
|
|
|
|
imap <C-a> <esc>wa
|
|
|
|
|
|
2011-12-16 12:01:38 +08:00
|
|
|
|
" ==== NERD tree
|
2012-01-21 10:01:06 +08:00
|
|
|
|
" Cmd-Shift-N for nerd tree
|
|
|
|
|
nmap <D-N> :NERDTreeToggle<CR>
|
2012-10-03 12:57:29 +08:00
|
|
|
|
" Open the project tree and expose current file in the nerdtree with Ctrl-\
|
|
|
|
|
nnoremap <silent> <C-\> :NERDTreeFind<CR>:vertical res 30<CR>
|
2011-12-16 12:01:38 +08:00
|
|
|
|
|
2014-02-16 11:08:32 +08:00
|
|
|
|
" ,q to toggle quickfix window (where you have stuff like Ag)
|
2011-12-17 16:46:02 +08:00
|
|
|
|
" ,oq to open it back up (rare)
|
2013-12-16 05:02:54 +08:00
|
|
|
|
nmap <silent> ,qc :cclose<CR>
|
2012-01-21 10:43:49 +08:00
|
|
|
|
nmap <silent> ,qo :copen<CR>
|
2011-12-17 16:46:02 +08:00
|
|
|
|
|
2012-03-13 01:05:56 +08:00
|
|
|
|
" move up/down quickly by using Cmd-j, Cmd-k
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" which will move us around by functions
|
2012-03-13 01:05:56 +08:00
|
|
|
|
nnoremap <silent> <D-j> }
|
|
|
|
|
nnoremap <silent> <D-k> {
|
|
|
|
|
autocmd FileType ruby map <buffer> <D-j> ]m
|
|
|
|
|
autocmd FileType ruby map <buffer> <D-k> [m
|
2012-03-13 01:25:32 +08:00
|
|
|
|
autocmd FileType rspec map <buffer> <D-j> }
|
2012-12-11 00:29:03 +08:00
|
|
|
|
autocmd FileType rspec map <buffer> <D-k> {
|
|
|
|
|
autocmd FileType javascript map <buffer> <D-k> }
|
|
|
|
|
autocmd FileType javascript map <buffer> <D-j> {
|
2012-01-22 05:45:12 +08:00
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
|
|
|
|
" Command-/ to toggle comments
|
|
|
|
|
map <D-/> :TComment<CR>
|
|
|
|
|
imap <D-/> <Esc>:TComment<CR>i
|
|
|
|
|
|
2012-01-26 04:10:02 +08:00
|
|
|
|
|
2012-02-11 06:59:48 +08:00
|
|
|
|
"Move back and forth through previous and next buffers
|
|
|
|
|
"with ,z and ,x
|
|
|
|
|
nnoremap <silent> ,z :bp<CR>
|
|
|
|
|
nnoremap <silent> ,x :bn<CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2011-12-16 16:04:14 +08:00
|
|
|
|
" ==============================
|
|
|
|
|
" Window/Tab/Split Manipulation
|
|
|
|
|
" ==============================
|
2012-01-03 04:27:36 +08:00
|
|
|
|
" Move between split windows by using the four directions H, L, I, N
|
2012-03-13 01:05:56 +08:00
|
|
|
|
nnoremap <silent> <C-h> <C-w>h
|
|
|
|
|
nnoremap <silent> <C-l> <C-w>l
|
|
|
|
|
nnoremap <silent> <C-k> <C-w>k
|
|
|
|
|
nnoremap <silent> <C-j> <C-w>j
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2013-12-21 10:13:26 +08:00
|
|
|
|
" Make gf (go to file) create the file, if not existent
|
|
|
|
|
nnoremap gf :e<cfile><CR>
|
|
|
|
|
nnoremap <C-w>f :sp +e<cfile><CR>
|
|
|
|
|
nnoremap <C-w>gf :tabe<cfile><CR>
|
|
|
|
|
|
2012-05-15 21:43:49 +08:00
|
|
|
|
" Zoom in and out of current window with ,gz
|
2012-01-25 06:45:15 +08:00
|
|
|
|
map <silent> ,gz <C-w>o
|
2011-12-16 16:04:14 +08:00
|
|
|
|
|
2011-12-16 14:20:51 +08:00
|
|
|
|
" Use numbers to pick the tab you want (like iTerm)
|
|
|
|
|
map <silent> <D-1> :tabn 1<cr>
|
|
|
|
|
map <silent> <D-2> :tabn 2<cr>
|
|
|
|
|
map <silent> <D-3> :tabn 3<cr>
|
|
|
|
|
map <silent> <D-4> :tabn 4<cr>
|
|
|
|
|
map <silent> <D-5> :tabn 5<cr>
|
|
|
|
|
map <silent> <D-6> :tabn 6<cr>
|
|
|
|
|
map <silent> <D-7> :tabn 7<cr>
|
|
|
|
|
map <silent> <D-8> :tabn 8<cr>
|
|
|
|
|
map <silent> <D-9> :tabn 9<cr>
|
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" Create window splits easier. The default
|
|
|
|
|
" way is Ctrl-w,v and Ctrl-w,s. I remap
|
|
|
|
|
" this to vv and ss
|
|
|
|
|
nnoremap <silent> vv <C-w>v
|
|
|
|
|
nnoremap <silent> ss <C-w>s
|
|
|
|
|
|
2012-04-16 03:31:56 +08:00
|
|
|
|
" Resize windows with arrow keys
|
2012-04-19 08:48:41 +08:00
|
|
|
|
nnoremap <D-Up> <C-w>+
|
|
|
|
|
nnoremap <D-Down> <C-w>-
|
|
|
|
|
nnoremap <D-Left> <C-w><
|
|
|
|
|
nnoremap <D-Right> <C-w>>
|
2012-03-09 05:20:05 +08:00
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" create <%= foo %> erb tags using Ctrl-k in edit mode
|
|
|
|
|
imap <silent> <C-K> <%= %><Esc>3hi
|
|
|
|
|
|
|
|
|
|
" create <%= foo %> erb tags using Ctrl-j in edit mode
|
|
|
|
|
imap <silent> <C-J> <% %><Esc>2hi
|
|
|
|
|
|
|
|
|
|
" ============================
|
|
|
|
|
" Shortcuts for everyday tasks
|
|
|
|
|
" ============================
|
|
|
|
|
|
|
|
|
|
" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename
|
|
|
|
|
" this is helpful to paste someone the path you're looking at
|
2012-04-06 01:03:40 +08:00
|
|
|
|
nnoremap <silent> ,cf :let @* = expand("%:~")<CR>
|
2012-04-15 07:40:50 +08:00
|
|
|
|
nnoremap <silent> ,cn :let @* = expand("%:t")<CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
|
|
|
|
"Clear current search highlight by double tapping //
|
|
|
|
|
nmap <silent> // :nohlsearch<CR>
|
|
|
|
|
|
2012-04-26 10:39:31 +08:00
|
|
|
|
"(v)im (c)ommand - execute current line as a vim command
|
2012-03-09 08:46:45 +08:00
|
|
|
|
nmap <silent> ,vc yy:<C-f>p<C-c><CR>
|
2011-12-13 10:21:42 +08:00
|
|
|
|
|
2012-04-26 10:39:31 +08:00
|
|
|
|
"(v)im (r)eload
|
|
|
|
|
nmap <silent> ,vr :so %<CR>
|
|
|
|
|
|
2011-12-13 10:21:42 +08:00
|
|
|
|
" Type ,hl to toggle highlighting on/off, and show current value.
|
|
|
|
|
noremap ,hl :set hlsearch! hlsearch?<CR>
|
|
|
|
|
|
|
|
|
|
" These are very similar keys. Typing 'a will jump to the line in the current
|
|
|
|
|
" file marked with ma. However, `a will jump to the line and column marked
|
|
|
|
|
" with ma. It’s more useful in any case I can imagine, but it’s located way
|
|
|
|
|
" off in the corner of the keyboard. The best way to handle this is just to
|
|
|
|
|
" swap them: http://items.sjbach.com/319/configuring-vim-right
|
|
|
|
|
nnoremap ' `
|
|
|
|
|
nnoremap ` '
|
2011-12-16 01:25:10 +08:00
|
|
|
|
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
2011-12-28 02:43:38 +08:00
|
|
|
|
" Tabularize - alignment
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
|
|
|
|
" Hit Cmd-Shift-A then type a character you want to align by
|
|
|
|
|
nmap <D-A> :Tabularize /
|
|
|
|
|
vmap <D-A> :Tabularize /
|
2011-12-18 17:05:38 +08:00
|
|
|
|
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
2011-12-18 17:38:03 +08:00
|
|
|
|
" SplitJoin plugin
|
2011-12-21 15:48:33 +08:00
|
|
|
|
" ============================
|
2011-12-18 17:38:03 +08:00
|
|
|
|
nmap sj :SplitjoinSplit<cr>
|
|
|
|
|
nmap sk :SplitjoinJoin<cr>
|
2011-12-18 17:05:38 +08:00
|
|
|
|
|
2012-04-04 17:21:19 +08:00
|
|
|
|
" Get the current highlight group. Useful for then remapping the color
|
|
|
|
|
map ,hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>
|
2012-05-15 21:43:49 +08:00
|
|
|
|
|
|
|
|
|
" Source current file Cmd-% (good for vim development)
|
|
|
|
|
map <D-%> :so %<CR>
|
2012-09-12 01:19:04 +08:00
|
|
|
|
|
|
|
|
|
" ,hp = html preview
|
|
|
|
|
map <silent> ,hp :!open -a Safari %<CR><CR>
|