" ======================================== " 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 _ imap _ imap - imap - " Change inside quotes with Cmd-" and Cmd-' nnoremap ci' nnoremap ci" " Add spaces around a symbol with Ctrl-Space nnoremap i a " Don't have to use Shift to get into command mode, just hit semicolon nnoremap ; : "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 " " the first quote will autoclose so you'll get 'foo' and hitting will " put the cursor right after the quote imap wa " ================== rails.vim " " Open corresponding unittest (or spec), alias for :AV in rails.vim nmap ,ru :AV " ==== NERD tree " Cmd-Shift-N for nerd tree nmap :NERDTreeToggle " ,q to toggle quickfix window (where you have stuff like GitGrep) " ,oq to open it back up (rare) nmap ,qc :cclose nmap ,qo :copen " move up/down quickly by using Ctrl-j, Ctrl-k " which will move us around by functions nnoremap } nnoremap { autocmd FileType ruby map ]m autocmd FileType ruby map [m " Open the project tree and expose current file in the nerdtree with Ctrl-\ nnoremap :NERDTreeFind " Command-/ to toggle comments map :TComment imap :TCommenti "open up a git grep line, with a quote started for the search nnoremap ,gg :GitGrep "" nnoremap ,gcp :GitGrepCurrentPartial " hit ,f to find the definition of the current class " this uses ctags. the standard way to get this is Ctrl-] nnoremap ,f " use ,F to jump to tag in a vertical split nnoremap ,F :let word=expand(""):vsp:wincmd w:exec("tag ". word) "toggle between last two buffers with Z (normally ctrl-shift-6) nnoremap ,z " ============================== " 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 H h nnoremap L l nnoremap I k nnoremap M j " Move between tabs with Ctrl-Shift-H and Ctrl-Shift-L map :tabprevious map :tabnext " Zoom in and out of current window with ,, map ,gz o " Use numbers to pick the tab you want (like iTerm) map :tabn 1 map :tabn 2 map :tabn 3 map :tabn 4 map :tabn 5 map :tabn 6 map :tabn 7 map :tabn 8 map :tabn 9 " Create window splits easier. The default " way is Ctrl-w,v and Ctrl-w,s. I remap " this to vv and ss nnoremap vv v nnoremap ss s "open the taglist (method browser) using ,t nnoremap ,T :TlistToggle " create <%= foo %> erb tags using Ctrl-k in edit mode imap <%= %>3hi " create <%= foo %> erb tags using Ctrl-j in edit mode imap <% %>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 ,cf :let @* = expand("%:p") "Clear current search highlight by double tapping // nmap // :nohlsearch " (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 ,cc yy:p " Type ,hl to toggle highlighting on/off, and show current value. noremap ,hl :set hlsearch! hlsearch? " Apple-* Highlight all occurrences of current word (like '*' but without moving) " http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches nnoremap :let @/='\<=expand("")\>':set hls " 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 :Tabularize / vmap :Tabularize / " ============================ " SplitJoin plugin " ============================ nmap sj :SplitjoinSplit nmap sk :SplitjoinJoin " ============================ " VimBookmarking " ============================ " " Set anonymous bookmarks nmap ,Bb :ToggleBookmark nmap ,Bn :NextBookmark nmap ,Bp :PreviousBookmark nmap ,Bc :ClearBookmarks " " ============================ " Abbreviations to use... " ============================ " snippets that are expanded with space abbr pry! require 'pry'; binding.pry " ============================ " vim-rspec " ============================ " Cmd-Shift-R for RSpec nmap :RunSpec " Cmd-Shift-L for RSpec Current Line nmap :RunSpecLine