20 KiB
VIM CHEATSHEET
WEBSITE: http://www.vim.org/
DOCUMENTATION: https://vim.sourceforge.io/docs.php
Table of Contents
- CURSOR MOVEMENTS
- BOOKMARKS
- INSERT MODE
- EDITING
- DELETING TEXT
- COPYING AND MOVING TEXT
- MACROS
- VISUAL MODE
- SPELLING
- EXITING
- SEARCH/REPLACE
- MULTIPLE FILES
- WINDOWS
- QUICKFIX WINDOW
- PROGRAMMING
Plugins
Plugins
CURSOR MOVEMENTS
hmove leftjmove downkmove uplmove rightwjump by start of words (punctuation considered words)Wjump by words (spaces separate words)ejump to end of words (punctuation considered words)Ejump to end of words (no punctuation)bjump backward by words (punctuation considered words)Bjump backward by words (no punctuation)gejump backward to end of words0(zero) start of line^first non-blank character of line$end of line-move line upwards, on the first non blank character+move line downwards, on the first non blank character<enter>move line downwards, on the first non blank charactergggo to first lineGgo to last linenGgo To line n:ngo To line n)move the cursor forward to the next sentence.(move the cursor backward by a sentence.{move the cursor a paragraph backwards}move the cursor a paragraph forwards]]move the cursor a section forwards or to the next {[[move the cursor a section backwards or the previous {CTRL-fmove the cursor forward by a screen of textCTRL-bmove the cursor backward by a screen of textCTRL-umove the cursor up by half a screenCTRL-dmove the cursor down by half a screenHmove the cursor to the top of the screen.Mmove the cursor to the middle of the screen.Lmove the cursor to the bottom of the screen.fxsearch line forward for 'x'Fxsearch line backward for 'x'txsearch line forward before 'x'Txsearch line backward before 'x'
BOOKMARKS
:markslist all the current marksmamake a bookmark named a at the current cursor position`ago to position of bookmark a'ago to the line with bookmark a`.go to the line that you last edited
INSERT MODE
istart insert mode at cursorIinsert at the beginning of the lineaappend after the cursorAappend at the end of the lineoopen (append) blank line below current lineOopen blank line above current lineEscexit insert mode
EDITING
rreplace a single character (does not use insert mode)Renter Insert mode, replacing characters rather than insertingJjoin line below to the current oneccchange (replace) an entire linecwchange (replace) to the end of wordCchange (replace) to the end of linesdelete character at cursor and substitute textSdelete line at cursor and substitute text (same as cc)xptranspose two letters (delete and paste, technically)uundoCTRL-rredo.repeat last command~switch caseg~iwswitch case of current wordgUiwmake current word uppercaseguiwmake current word lowercasegU$make uppercase until end of linegu$make lowercase until end of line>>indent line one column to right<<indent line one column to left==auto-indent current lineddpswap current line with nextddkPswap current line with previous:%retabfix spaces / tabs issues in whole file:r [name]insert the file [name] below the cursor.:r !{cmd}execute {cmd} and insert its standard output below the cursor.
DELETING TEXT
xdelete current characterXdelete previous characterdwdelete the current worddddelete (cut) a lineDdelete from cursor to end of line:[range]ddelete [range] lines
COPYING AND MOVING TEXT
ywyank wordyyyank (copy) a line2yyyank 2 linesy$yank to end of linepput (paste) the clipboard after cursor/current linePput (paste) before cursor/current line:set pasteavoid unexpected effects in pasting:registersdisplay the contents of all registers"xywyank word into register x"xyyyank line into register x:[range]y xyank [range] lines into register x"xpput the text from register x after the cursor"xPput the text from register x before the cursor"xgpjust like "p", but leave the cursor just after the new text"xgPjust like "P", but leave the cursor just after the new text:[line]put xput the text from register x after [line]
MACROS
qastart recording macro 'a'qend recording macro@areplay macro 'a'@:replay last command
VISUAL MODE
vstart visual mode, mark lines, then do command (such as y-yank)Vstart linewise visual modeomove to other end of marked areaUupper case of marked areaCTRL-vstart visual block modeOmove to other corner of blockawmark a wordaba () block (with braces)aba {} block (with brackets)ibinner () blockibinner {} blockEscexit visual mode
VISUAL MODE COMMANDS
>shift right<shift leftcchange (replace) marked textyyank (copy) marked textddelete marked text~switch case
SPELLING
]snext misspelled word[sprevious misspelled wordzgadd word to wordlistzugundo last add wordz=suggest word
EXITING
:qquit Vim. This fails when changes have been made.:q!quit without writing.:cqquit always, without writing.:wqwrite the current file and exit.:wq!write the current file and exit always.:wq {file}write to {file}. Exit if not editing the last:wq! {file}write to {file} and exit always.:[range]wq[!]same as above, but only write the lines in [range].ZZwrite current file, if modified, and exit.ZQquit current file and exit (same as ":q!").
SEARCH/REPLACE
/patternsearch for pattern?patternsearch backward for patternnrepeat search in same directionNrepeat search in opposite direction*search forward, word under cursor#search backward, word under cursor:%s/old/new/greplace all old with new throughout file:%s/old/new/gcreplace all old with new throughout file with confirmation:argdo %s/old/new/gc | wqopen multiple files and run this command to replace old with new in every file with confirmation, save and quit
MULTIPLE FILES
:e filenameedit a file in a new buffer:tabe filenameedit a file in a new tab (Vim7, gVim):lslist all buffers:bngo to next buffer:bpgo to previous buffer:bddelete a buffer (close a file):b1show buffer 1:b vimrcshow buffer whose filename begins with "vimrc"
WINDOWS
:sp fsplit open f:vsp fvsplit open fCTRL-w ssplit windowsCTRL-w wswitch between windowsCTRL-w qquit a windowCTRL-w vsplit windows verticallyCTRL-w xswap windowsCTRL-w hleft windowCTRL-w jdown windowCTRL-w kup windowCTRL-w lright windowCTRL-w +increase window heightCTRL-w -decrease window heightCTRL-w <increase window widthCTRL-w >decrease window widthCTRL-w =equal windowCTRL-w oclose other windows
QUICKFIX WINDOW
copenopen quickfix windowccloseclose quickfix windowcc [nr]display error [nr]cfirstdisplay the first errorclastdisplay the last error[count]cndisplay [count] next error[count]cpdisplay [count] previous error
PROGRAMMING
%show matching brace, bracket, or parenthesegfedit the file whose name is under or after the cursorgdwhen the cursor is on a local variable or function, jump to its declaration''return to the line where the cursor was before the latest jumpgireturn to insert mode where you inserted text the last timeCTRL-omove to previous position you were atCTRL-imove to more recent position you were at
PLUGINS > ACK
:AckSearch recursively in directoryoto open (same as enter)goto preview file (open but maintain focus on ack.vim results)tto open in new tabTto open in new tab silentlyqto close the quickfix window
PLUGINS > CHEAT
:Cheatopen cheat sheet (with autocomplete)<leader>chopen cheat sheet for word under the cursor
PLUGINS > GIST
:Gistpost whole text to gist:Gist XXXXXget gist XXXXX:Gist -llist my gists
PLUGINS > GUNDO
:GundoToggleshow undo tree
PLUGINS > LUSTYJUGGLER
<Leader>ljshow open buffers
PLUGINS > NERDCOMMENTER
<leader>cccomment out line(s)<leader>c<space>toggle the comment state of the selected line(s)
PLUGINS > NERDTREE
:NERDTreeToggleshow / hide file browser:NERDTreeFindshow current file in file browser:Bookmark namebookmark the current node as "name"
FILE
oopen in prev windowgopreviewtopen in new tabTopen in new tab silentlyiopen splitgipreview splitsopen vsplitgspreview vsplit
DIRECTORY
oopen & close nodeOrecursively open nodexclose parent of nodeXclose all child nodes of current node recursivelyeexplore selected dir
BOOKMARK
oopen bookmarktopen in new tabTopen in new tab silentlyDdelete bookmark
TREE NAVIGATION
Pgo to rootpgo to parentKgo to first childJgo to last childCTRL-jgo to next siblingCTRL-kgo to prev sibling
FILESYSTEM
Cchange tree root to the selected dirumove tree root up a dirUmove tree root up a dir but leave old root openrrefresh cursor dirRrefresh current rootmshow menucdchange the CWD to the selected dir
TREE FILTERING
Ihidden filesffile filtersFfilesBbookmarks
OTHER
qclose the NERDTree windowAzoom (maximize-minimize) the NERDTree window?toggle help
PLUGINS > PDV
CTRL-Pgenerate PHP DOC
PLUGINS > PICKACOLOR
:PickHEXchoose color in system color picker
PLUGINS > SNIPMATE
<tab>expand snippet
PLUGINS > SPARKUP
CTRL-eexecute sparkup (zen coding expansion)CTRL-njump to the next empty tag / attribute
PLUGINS > SURROUND
cs'"change surrounding quotes to double-quotescs(}change surrounding parens to bracescs({change surrounding parens to braces with spaceds'delete surrounding quotesdstdelete surrounding tagsysiw[surround inner word with bracketsvees'surround 2 words (ee) with quotes '
PLUGINS > TABULAR
:Tabularize /,line the selected lines up on the commas
PLUGINS > TAGLIST
:TlistToggleopen / close taglist window<enter>jump to tag or file<space>display the tag prototype
PLUGINS > UNIMPAIRED
[spacenew line above]spacenew line below[eexchange line above]eexchange line below[xXML encode]xXML decode (with htmlentities)[qjump to previous quickfix item]qjump to next quickfix item[Qjump to first quickfix item]Qjump to last quickfix item
PLUGINS > VIM-FUGITIVE
:Gitrun a git command:Gstatusgit status : - to (un)stage , p to patch, C to commit:Gcommitgit commit:Greadempty the buffer and revert to the last commit:Gwritewrite the current file and stage the results:Gmovegit mv:Gremovegit rm:Gloggit log:Gdiffperform a vimdiff against the current file of a certain revision:Gblameopen blame information in a scroll bound vertical splitt:Gbrowseopen github
PLUGINS > VIM-MARKDOWN-PREVIEW
:Mmpreview markdown document in webbrowser
PLUGINS > VIM-PEEPOPEN
<Leader>popen the current directory with the peepopen application (fuzzy search)
PLUGINS > VIM-SYMFONY
:Sviewopen template file:Sactionopen action file:Smodelopen model file:Sfilteropen filter file:Sformopen form file:Spartialopen partial file / write selected content in partial + include:Scomponentopen component file / write selected content in component + include:Salternateopen alternate model file (class - table class):Symfonyexecute task
PERSONAL .VIMRC
-
<leader>evedit vimrc file -
<leader>svreload vimrc file -
<leader>shshow syntax highlighting groups for word under cursor -
<space>page down -
jjexit insertion mode -
<leader>qclose the current window -
<leader>/clear the search register -
<leader>htoggle hidden characters -
<leader>Wstrip all trailing whitespace -
CTRL-hgo to left window -
CTRL-jgo to down window -
CTRL-kgo to top window -
CTRL-lgo to right window -
<leader>wopen vertical split window and activate -
%%will expand to current directory -
<leader>ewopen file from current directory -
<leader>esopen file in split window from current directory -
<leader>cdchange directory to parent dir of current file -
##will expand to webroot -
:Wrapwrap text -
<F2>toggle wrapped text -
<F3>toggle spell check -
<F4>toggle light/dark background -
<F5>underline with dashes -
<F6>underline with double lines -
<leader><up>bubble line(s) up -
<leader><down>bublle line(s) down -
:Ltagload tags file -
:Projectcd to project and load tags file -
<leader>tshow current tag for word under cursor -
<leader>stshow current tag for word under cursor in split window -
<leader>tjshow current tag list for word under cursor -
<leader>stjshow current tag list for word under cursor in split window -
CTRL-<space>show omnicomplete menu -
<leader>bsurround with strong tags -
<leader>isurround with em tags -
CTRL-pgenerate PHP DOC -
<leader>arun Ack -
<leader>mdpreview markdown -
<leader>spreview in safari -
<leader>xcolorpicker -
<leader>ntoggle Nerdtree -
<leader>Nclose Nerdtree -
<leader>ffind current file in Nerdtree -
<leader>ltoggle Taglist -
<leader>Lclose Taglist -
<leader>phset filetype to php.html -
<leader>rreload all snipmate snippets -
CTRL-<tab>switch between buffers -
CTRL-ygo to next tag of attribute in sparkup plugin -
<leader>gtoggle Gundo window -
IMG<CR>show image browser to insert image tag with src, width and height -
binsert image tag with dimensions from NERDTree http://stackoverflow.com/questions/5707925/vim-image-placement