hjkl
- left, down, up, right-
- up char+
- down charb
- before wordB
- before code wordw
- next wordW
- next code word0
- line start^
- first char$
- line ende
- word endE
- code word end{
or}
- beginning or end of the paragraph(
or)
- beginning or end of the sentence%
- bounce between parentheses, quotes, and language specific blocks
gm
- go to middle of lineg0
- go to line startg^
- go to first charg$
- got to line endge
- previous end of wordgE
- previous end of code wordgk
- go up screen linegj
- go down screen line
fx
- find next xFx
- find previous x;
- repeat latest jump forward,
- repeat latest jump backward
H
- high, top of screenL
- low, bottom of screenM
- medium, center of screenzt
- scroll current line to top of screenzz
- scroll current line to middle of screenzb
- scroll current line to bottom of screen
C-b
- scroll full screen before / upC-u
- scroll half screen upC-y
- scroll one line upC-e
- scroll one line downC-d
- scroll half screen downC-f
- scroll full screen forward / down
12G
or12gg
- jumps to line 12gg
- jumps to top of the documentG
- jumps to bottom of the documentg C-g
- displays current position in the fileH
- high, jumps to the top of the viewM
- middle, jumps to the middle of the viewL
- low, jumps to the bottom of the view
ma
- create a mark named 'a', lowercase are file-specific, uppercase are global- ``a` - jump to the exact line and column
'a
- jump to beginning of maked line onlyd't
- delete to markt
- ``0-
9
- the location of the cursor when you last exited Vim "
and `` - the position of the cursor before the latest jump'.
and ``.` - Location of the last edit:marks
- to see a list of marks
i
- insert text before the cursora
- insert text after the cursorI
- move to first non-blank character of line and insertA
- append text at the end of the lineo
- open a new line belowO
- open a new line above
.
- repeat the last command@:
- repeat the last executed command
r
- replace a single characterR
- go to replace modec
- change: delete words and switch to insert modecc
orC
- change the whole line
x
- delete a characterdd
orD
- delete a line
y
- yank the current selectionyy
orY
- yank the line"ayy
- yank line into register a"+yy
- tank to the system clipboard
"ap
- paste from register a""
- the unnamed register, contained the last deleted text"0p
- paster from the zero register - contents of the last yank command:registers
- shows contents of all registers"+
- paste from clipboard
J
- join the previous line with the current, adds spacegJ
- join previous line without adding space
<<
- indent left>>
- indent rightC-t
- indent right from insert modeC-d
- indent left from insert mode
vit
- operator extent object- operators: change, delete, yank, visual
- extent: all delimeters, inner object
- object: word, Word, sentence, paragraphm tag, ", ', [, {
o
- in visual mode, switches which end is being manipulated
u
- undoes 1 actionC-r
- redoes 1 action
/query
or?query
- search down or upn
- next matchN
- previous match*
- next current word#
- previous current wordg*
- next partial matchg#
- previous partial match
:%s/search/replace/gc
%
- search the current bufferg
- global: search all occurrencesc
- confirm: ask for confirmation on each matchi
- ignore caseI
- case-sensitiven
- show number of matchesp
-print matching lines
SHF-V
- select the whole lineC- V
- visual mode at character
:pwd
- print working directory:cd
- change working directory:set autochdir
- automatically use current file directory as working directory:e filename
- to edit a filegf
- go to file, open the file that under the cursor
i
- thin, long, wide, or tree listingss
- sort on name, time, or file sizer
- reverse sort ordergh
- hide or unhide dotfiles<Enter>
- open the file or directoryo
- open in a new splitx
- view file with associated applicationd
- make directoryD
- delete the file or directoryR
- rename the file or directory-
- go up a directory
\
- custom shortcut key, backslash by default
C-w, s
- horizontal splitC-w, v
- vertical split
C-w, c
- close windowC-w, q
- close splitC-w, o
- make current window the only one
C-w, C-w
- cycle between splits clockwiseC-w, w
- cycle between splits, as aboveC-w, W
- cycle between splits, counter clockwiseC-w, p
- previous windowC-w, t
- top leftC-w, b
- bottom rightC-w, j
- switch focus to the downward split, can also useh k l
C-w, J
- Move split one down, can also useh k l
C-w, r
- Rotate splits clockwiseC-w, R
- Rotate splits counter-clockwiseC-w, x
- Exchange the current window with the next oneC-w, T
- Moves the current split to a new tab
:q
- closes split:sp filename
- horizontal split:vsp filename
or:vs filename
- vertical split
:tabnew
- map to<leader>tt
:tabedit
- map to<leader>te
:tabclose
- map to<leader>tc
:tabonly
- map to<leader>to
:tabnext
- map to<leader>tn
:tabprevious
- map to<leader>tp
:tabfirst
- map to<leader>tf
:tablast
- map to<leader>tl
:tabmove
- map to<leader>tm
:ls
- list all buffers:b1
- switches to the first buffer, can be a different number:bp
- switched to the previous buffer:bn
- next buffer:bp
- previous buffer:bd
- delete buffer (close file):bf
- first buffer:bl
- last buffer:ba
- open a window for evey buffer - AllC-^
- switch to last buffer
C-z
- suspend Vim,%vim
to go back:! git status
- execute external commands from vim
zM
- fold allzc
- close foldza
- toggle foldzo
- open foldzR
- open all foldszk
- move up a foldzj
- move down a fold
C-n
- Activate completion, or completion menu for multiple options
:set nopaste
- turns off auto indentation and bracket matching for pasting:set paste
- opposite of:set nopaste
:set copyindent
- can also work
:retab
- replace all tabs with spaces in the current bufferggVG=
- visually select the entire buffer, format the selection with =gq
- reflow paragraph to 80 characters wide
:h a<tab>
- search and autocomplete help topicC-t
- jump backC-]
- open link:helptags ~/.vim/doc
- import standard plugin docs:call pathogen#helptags()
- import docs with the pathogen plugin system
brew install macvim
- to install from Homebrewcp mvim /usr/local/bin
- to copy the mvim script to the path
cst
- change surround tagdst
- delete surround tagVs
- add a tag around text:h surround
- plugin documentation
<F5>
- purge the cache for the current directory to get new files<c-f>
and<c-b>
- to cycle between modes<c-d>
- filename only search instead of full path<c-r>
- regexp mode<c-j>
and<c-k
> or the arrows - to navigate the results list<c-t>
or<c-v>
,<c-x>
- to open the selected entry in tab / split<c-n>
and<c-p>
- to select next / previous string in the prompt history<c-y>
- create a new file and its parent directories<c-z>
- to mark / unmark multiple files,<c-o>
to open..
- summit two or more dots to go up th edirectory tree:25
- command to execute it on the opening files, jump to line 25
[count]<leader>cc
- |ComComment| Comment out the current line or text selected in visual mode.[count]<leader>cn
- |ComNestedComment| Same as cc but forces nesting.[count]<leader>c
- |ComToggleComment| Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa.[count]<leader>cm
- |NERDComMinimalComment| Comments the given lines using only one set of multipart delimiters.[count]<leader>ci
- |NERDComInvertComment| Toggles the comment state of the selected line(s) individually.[count]<leader>cs
- |NERDComSexyComment| Comments out the selected lines ``sexily''[count]<leader>cy
- |NERDComYankComment| Same as cc except that the commented line(s) are yanked first.<leader>c$
- |NERDComEOLComment| Comments the current line from the cursor to the end of line.<leader>cA
- |NERDComAppendComment| Adds comment delimiters to the end of line and goes into insert mode between them.|NERDComInsertComment|
- Adds comment delimiters at the current cursor position and inserts between. Disabled by default.<leader>ca
- |NERDComAltDelim| Switches to the alternative set of delimiters.[count]<leader>cl
[count]<leader>cb |NERDComAlignedComment|
- Same as |NERDComComment| except that the delimiters are aligned down the left side (cl) or both sides (cb).[count]<leader>cu |NERDComUncommentLine|
- Uncomments the selected line(s).