234 lines
7.5 KiB
VimL
234 lines
7.5 KiB
VimL
" Arpeggio lets us define key-chord combos (simultaneous key presses)
|
||
call arpeggio#load()
|
||
|
||
" ========================================
|
||
" General vim sanity improvements
|
||
" ========================================
|
||
"
|
||
"
|
||
" Change leader to a comma because the backslash is too far away
|
||
" That means all \x commands turn into ,x
|
||
let mapleader=","
|
||
|
||
" 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)
|
||
nnoremap ,ow "_diwhp
|
||
|
||
"make Y consistent with C and D
|
||
nnoremap Y y$
|
||
|
||
" ========================================
|
||
" RSI Prevention - keyboard remaps
|
||
" ========================================
|
||
" Certain things we do every day as programmers stress
|
||
" out our hands. For example, typing underscores and
|
||
" dashes are very common, and in position that require
|
||
" a lot of hand movement. Vim to the rescue
|
||
"
|
||
" 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> -
|
||
|
||
" gary bernhardt's hashrocket
|
||
imap <c-l> <space>=><space>
|
||
|
||
" Use the two first fingers on both sides of the keyboard
|
||
" simultaneously to go to the beginning or end of line
|
||
Arpeggio nnoremap jk $
|
||
Arpeggio nnoremap fd 0
|
||
|
||
" Change inside quotes with Cmd-" and Cmd-'
|
||
nnoremap <D-'> ci'
|
||
nnoremap <D-"> ci"
|
||
|
||
" Add spaces around a symbol with Ctrl-Space
|
||
nnoremap <C-Space> i <esc><right>a <esc>
|
||
|
||
"Go to last edit location with ,.
|
||
nnoremap ,. '.
|
||
|
||
"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
|
||
|
||
" ==== NERD tree
|
||
" Cmd-Shift-N for nerd tree
|
||
nmap <D-N> :NERDTreeToggle<CR>
|
||
|
||
" ,q to toggle quickfix window (where you have stuff like GitGrep)
|
||
" ,oq to open it back up (rare)
|
||
nmap <silent> ,qc :cclose<CR>
|
||
nmap <silent> ,qo :copen<CR>
|
||
|
||
" move up/down quickly by using Cmd-j, Cmd-k
|
||
" which will move us around by functions
|
||
nnoremap <silent> <D-j> }
|
||
nnoremap <silent> <D-k> {
|
||
autocmd FileType ruby map <buffer> <D-j> ]m
|
||
autocmd FileType ruby map <buffer> <D-k> [m
|
||
autocmd FileType rspec map <buffer> <D-j> }
|
||
autocmd FileType rspec map <buffer> <D-k> {
|
||
|
||
" Open the project tree and expose current file in the nerdtree with Ctrl-\
|
||
nnoremap <silent> <C-\> :NERDTreeFind<CR>
|
||
|
||
" Command-/ to toggle comments
|
||
map <D-/> :TComment<CR>
|
||
imap <D-/> <Esc>:TComment<CR>i
|
||
|
||
"GitGrep - open up a git grep line, with a quote started for the search
|
||
nnoremap ,gg :GitGrep ""<left>
|
||
"GitGrep Current Partial
|
||
nnoremap ,gcp :GitGrepCurrentPartial<CR>
|
||
"GitGrep Current File
|
||
nnoremap ,gcf :call GitGrep(expand("%:t:r"))<CR>
|
||
|
||
" hit ,f to find the definition of the current class
|
||
" this uses ctags. the standard way to get this is Ctrl-]
|
||
nnoremap <silent> ,f <C-]>
|
||
|
||
" use ,F to jump to tag in a vertical split
|
||
nnoremap <silent> ,F :let word=expand("<cword>")<CR>:vsp<CR>:wincmd w<cr>:exec("tag ". word)<cr>
|
||
|
||
" use ,gf to go to file in a vertical split
|
||
nnoremap <silent> ,gf :vertical botright wincmd f<CR>
|
||
|
||
|
||
"Move back and forth through previous and next buffers
|
||
"with ,z and ,x
|
||
nnoremap <silent> ,z :bp<CR>
|
||
nnoremap <silent> ,x :bn<CR>
|
||
|
||
" ==============================
|
||
" Window/Tab/Split Manipulation
|
||
" ==============================
|
||
" Move between split windows by using the four directions H, L, I, N
|
||
" (note that I use I and N instead of J and K because J already does
|
||
" line joins and K is mapped to GitGrep the current word
|
||
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
|
||
|
||
" Zoom in and out of current window with ,,
|
||
map <silent> ,gz <C-w>o
|
||
|
||
" 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>
|
||
|
||
" 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
|
||
|
||
" Resize windows with arrow keys
|
||
nnoremap <Up> <C-w>+
|
||
nnoremap <Down> <C-w>-
|
||
nnoremap <Left> <C-w><
|
||
nnoremap <Right> <C-w>>
|
||
|
||
" 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
|
||
nnoremap <silent> ,cf :let @* = expand("%:~")<CR>
|
||
nnoremap <silent> ,cn :let @* = expand("%:t")<CR>
|
||
|
||
"Clear current search highlight by double tapping //
|
||
nmap <silent> // :nohlsearch<CR>
|
||
|
||
" (c)opy (c)ommand - which allows us to execute
|
||
" the line we're looking at (it does so by yy-copy, colon
|
||
" to get to the command mode, C-f to get to history editing
|
||
" p to paste it, C-c to return to command mode, and CR to execute
|
||
nmap <silent> ,vc yy:<C-f>p<C-c><CR>
|
||
|
||
" Type ,hl to toggle highlighting on/off, and show current value.
|
||
noremap ,hl :set hlsearch! hlsearch?<CR>
|
||
|
||
" clear highlights by hitting enter
|
||
noremap <CR> :nohlsearch<CR>
|
||
|
||
" Apple-* Highlight all occurrences of current word (like '*' but without moving)
|
||
" http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches
|
||
nnoremap <D-*> :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<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 ` '
|
||
|
||
" ============================
|
||
" Tabularize - alignment
|
||
" ============================
|
||
" Hit Cmd-Shift-A then type a character you want to align by
|
||
nmap <D-A> :Tabularize /
|
||
vmap <D-A> :Tabularize /
|
||
|
||
" ============================
|
||
" SplitJoin plugin
|
||
" ============================
|
||
nmap sj :SplitjoinSplit<cr>
|
||
nmap sk :SplitjoinJoin<cr>
|
||
|
||
" ============================
|
||
" VimBookmarking
|
||
" ============================
|
||
"
|
||
" Set anonymous bookmarks
|
||
nmap ,Bb :ToggleBookmark<cr>
|
||
nmap ,Bn :NextBookmark<cr>
|
||
nmap ,Bp :PreviousBookmark<cr>
|
||
nmap ,Bc :ClearBookmarks<cr>
|
||
"
|
||
" ============================
|
||
" Abbreviations to use...
|
||
" ============================
|
||
" snippets that are expanded with space
|
||
abbr pry! require 'pry'; binding.pry
|
||
|
||
" ============================
|
||
" vim-ruby-conque
|
||
" ============================
|
||
" Cmd-Shift-R for RSpec
|
||
nmap <silent> <D-R> :call RunRspecCurrentFileConque()<CR>
|
||
" Cmd-Shift-L for RSpec Current Line
|
||
nmap <silent> <D-L> :call RunRspecCurrentLineConque()<CR>
|
||
|
||
" 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>
|