As configured in my dotfiles
- Your problem with Vim is that you don't grok vi (on StackOverflow)
- Coming Home to Vim
- VimCasts.org
- Vim Galore
- Vim Adventures!
- How I Boosted my Vim
$ vimtutor
$ cd ~/.vim/bundle
$ git clone repo
$ source ~/.vimrc (my .vimrc includes a line that reloads plugins w pathogen)
<Leader>ev ==> edit .vimrc
<Leader>sv ==> source .vimrc
* a WORD is any group of chars delimited by white space
* a word is any group of chars delimited by white space OR special characters
* "Motions" move the cursor (h, j, k, l, w, b, /)
* "Operators" act on a region of text (d, ~, gU, >)
* "Text Objects" act on the surrounding area, opposed to motions that act into one direction (daw, ci(, vip)
* Ctrl-w <Arrow> ==> switch windows
* Ctrl-w Ctrl-w ==> toggle last window
* gt ==> go to next tab
* gT ==> go to previous tab
* <Count>gt ==> go to tab number <Count>
* Ctrl-w H ==> make current window full height and move to far left
* Ctrl-w K ==> make current window full width and move to top
* Ctrl-w = ==> make all windows equal size
* Ctrl-w <Count>> ==> resize <Count> columns bigger
* Ctrl-w <Count>< ==> resize <Count> columns smaller
* Ctrl-w <Count>+ ==> resize <Count> rows bigger
* Ctrl-w <Count>- ==> resize <Count> rows smaller
* <Leader>bl ==> (buffergator) open buffer list
* <Leader>jj ==> (buffergator) open previous buffer
* <Leader>kk ==> (buffergator) open next buffer
* <Leader>bq ==> (buffergator) close current buffer and open previous
* <Leader>T ==> (buffergator) open new empty buffer
* [hjkl] ==> go left, down, up, right
* [count] [hjkl] ==> go [count] chars left, down, up, right
* 0 ==> go to the starting of the current line
* $ ==> go to the end of the current line
* ^ ==> go to the first non blank character of the line
* g_ ==> go to the last non blank character of the line
* g ==> go to first line
* G ==> go to last line
* [count] G ==> go to [count] line number
* H ==> Go to the first line of current screen.
* M ==> Go to the middle line of current screen.
* L ==> Go to the last line of current screen.
* Ctrl-u, Ctrl-d ==> up half page, down half page
* Ctrl-b, Ctrl-f ==> up (back) full page, down (forward) full page
* w or W ==> beginning of next word or WORD
* b or B ==> beginning of previous word or WORD (current word if not already at beginning of word)
* e or E ==> end of current word or WORD (next word if already at end of current word)
* { or } ==> beginning/end of current paragraph (a paragaph is delimited by empty lines)
* / [pattern] ==> search for next occurrence of [pattern]
* ? [pattern] ==> search for previous occurrence of [pattern]
* n ==> go to next matching search item (will search in same direction as search)
* ==> go to next occurrence of WORD under cursor
* # ==> go to previous occurrence of WORD under cursor
* Ctrl-n ==> (vim-multiple-cursors) multi-cursor select word (or next match if already in multi-cursor mode)
* Ctrl-p ==> (vim-multiple-cursors) multi-cursor select previous word
* Ctrl-x ==> (vim-multiple-cursors) multi-cursor skip currently selected word
* Ctrl-i or Ctrl-o ==> go to next/prev jump made (can travel between buffers)
* g, or g; ==> go to next/prev change made
* m <Letter> ==> mark current location with <Letter>
* ' <Letter> ==> go to line of the <Letter> mark (if exists)
* ` <Letter> ==> go to exact cursor location of the <Letter> mark (if exists)
* :marks ==> display all marks
* <Leader>p ==> CtrlP find files
* <Leader>bb ==> CtrlP find buffers
* <Leader>bs ==> CtrlP find most recently used files
* <Leader>bm ==> CtrlP find mixed results
* % or <Tab> ==> find nearest/toggle current open/close structure (methods, html blocks, do/end blocks, etc)
* :A ==> (vim-rails & projectionist) go to alternate file (i.e. controller test if in controller file)
* :R ==> (vim-rails) go to related file
* <Leader>Rc ==> (vim-rails) go to related controller file (i.e. controller if in related view or model)
* <Leader>Rv ==> (vim-rails) go to related view file (i.e. view if in related controller or model)
* <Leader>Rm ==> (vim-rails) go to related model file (i.e. model if in related controller or view)
* <Leader>A ==> (ack.vim) do Ack search
* gf ==> (vim-rails + builtin) go to definition of whatever is under cursor
* <Ctrl>] ==> go to tag
* <Ctrl>T ==> return from tag jump
* :<Count> >> ==> indent next <Count> lines
* :<Start>,<End> > ==> indent lines <Start> to <End>, inclusive
* Ctrl-t ==> insert indent at start of line
* Ctrl-d ==> remove indent at start of line
* dd or d_ ==> cut line
* yy or y_ ==> copy line
* dw ==> cut word
* cw ==> change word (delete and go to insert mode)
* d<Count>w ==> cut <Count> words
* d<Count>d ==> cut <Count> lines
* ys<Text Object><Delimiter> ==> surround <Text Object> with <Delimiter>
* cs<TO><OldD><NewD> ==> change surrounding <OldD> to <NewD>
* ds<TO><Delimiter> ==> remove surrounding <Delimiter>
* s ==> deletes current char and enters insert mode
* vat ==> select entire tag
za ==> toggle fold
zc ==> close current fold
zo ==> open current fold
zj ==> navigate to next fold below
zk ==> navigate to next fold above
zM ==> fold everything
zR ==> unfold everything
1. v
2. i or a
3. (object)
* wW => word or WORD
* s => sentence
* p => paragraph
* b => block (parens)
* B => block (Braces)
* t => tag (xml tag)
* < => block (gt lt)
* [ => block (brackets)
* ' or " or ` => quotes
* iI => indent (courtesy of vim-indent-object plugin)
:e [filename/url] ==> open file for editing (if no file named, open new file or reload current file)
:r [filename/url] ==> inject file at cursor
:[count]r [filename/url] ==> inject file at line number [count]
:r! [command] ==> inject results of command at cursor
:w [filename] ==> write to file (if no file named, write to currently open file
:q ==> quit
:split [filename/url] ==> open file in horizontal split
:vsplit [filename/url] ==> open file in vertical split
NOTE: add ! to force any of the above
* <Leader>ev ==> edit .vimrc
* <Leader>sv ==> source .vimrc
* <C-k> ==> move current line up
* <C-j> ==> move current line down
* <Leader><Space> ==> clear previous search
* <Tab> ==> jump to opposite tag
* :w!! ==> retroactively sudo edit the current file
* <F3> ==> toggle line numbering setting
* <S-Enter> ==> insert blank line below cursor w/out leaving normal mode
* <Leader>v ==> reselect recently pasted text (for adding indent, etc)
* jj ==> escape from insert mode
* jjj ==> escape from insert mode and write to the buffer
* .log<Tab> ==> surrounds text with console.log();
* jj ==> escapes from insert mode
* Ctrl-n ==> (vim-multiple-cursors) highlight current word/next match in multiple cursor mode
* <Leader>n ==> (nerdtree) toggle NERDTree
* :A ==> (vim-rails) go to alternate file (i.e. controller test if in controller file)
* :AV ==> (vim-rails & projectionist) open alternate file in vertical split
* :AS ==> (vim-rails & projectionist) open alternate file in horizontal split
* :AT ==> (vim-rails & projectionist) open alternate file in tab
* :A <Filename> ==> (vim-rails & projectionist) open file relative to current project
* :R :RV :RS :RT ==> (vim-rails) related file
* <Leader>Rc ==> (vim-rails) go to related controller file (i.e. controller if in related view or model)
* <Leader>Rv ==> (vim-rails) go to related view file (i.e. view if in related controller or model)
* <Leader>Rm ==> (vim-rails) go to related model file (i.e. model if in related controller or view)
* <Leader>p ==> (ctrlp) open ctrlp window
* <Leader>bb ==> (ctrlp) open ctrlp buffer list
* <Leader>bs ==> (ctrlp) open ctrlp mru list
* <Leader>bm ==> (ctrlp) open ctrlp mixed list
* <Leader>fu ==> (ctrlp-funky) open ctrlp function list
* <Leader>fU ==> (ctrlp-funky) function list narrowed to word under cursor
* <Leader>t ==> (dispatch) run :Dispatch
* <Leader>bl ==> (buffergator) open buffer list
* <Leader>jj ==> (buffergator) open previous buffer
* <Leader>kk ==> (buffergator) open next buffer
* <Leader>bq ==> (buffergator) close current buffer and open previous
* <Leader>T ==> (buffergator) open new empty buffer
* <Leader>gl ==> (gist-vim) open list of gists
* <Leader>gp ==> (gist-vim) save current file as private gist
* <Leader>gP ==> (gist-vim) save current file as public gist
* <Leader>c<Space> ==> (nerdcommenter) toggle comment on current line
* ys<TO><D> ==> (vim-surround) surround <Text Object> with <Delimiter>
* cs<TO><OldD><NewD> ==> (vim-surround) change surrounding <OldD> to <NewD>
* ds<TO><D> ==> (vim-surround) remove surrounding <Delimiter>
* :Calendar ==> (vim-calendar) show calendar (press E to view event details)
* :HackerNews ==> (vim-hackernews) show hackernews front page (press O to open link in browser)
* gS ==> (splitjoin) split a single line of code into multi
* gJ ==> (splitjoin) join multi into a single line of code
- Put % before any vim command line command to apply it to all lines!
- Use the "norm" command to execute code in normal mode
- Vim also has “adjectives” like “inside” and “around” (i and a) that let you craft sentences like “change inside parenthesis” (ci( or cib). Or "delete around word" (daw). Or even "visually select inside paragraph" (vip)
- You probably only ever use caps lock on accident! Remap it to something useful like Ctrl or Esc! (I do Ctrl!)
- The :finish command will make a vim script stop processing. It's a great tool for debugging a bad plugin by manually binary searching a file for error-causing code (add :finish in the middle of .vimrc, source it, and see if bug persists. Then, move :finish up or down and keep narrowing down until bug is found)
- You can quickly paste the results of a linux command into a vim doc with :r !
- When in command mode in vim, you can type % and press to see the path of the current file