Jumping around
CTRL-]
: jump to tag under cursor, also works when browsing helpCTRL-O
/CTRL-I
: jump to previous/next positiongf
: open file path under cursor (cf:he includeexpr
)CTRL-W gf
: open file path under cursor in a new tab, useful when opening directories
Quickfix list
:cw
: opens the quickfix window:cn
/:cp
: jumps to next/previous errorSHIFT-ENTER
: in the quickfix window, jump to the current line match
Tags
g]
: displays all tags matching word under cursor:ts[elect] /<tag-pattern>
: display all tags matchingg CTRL-}
: displays all tags matching word under cursorCTRL-W }
: displays symbol defintion in preview window
Commands
!<shell_cmd>
: runs shell command (cfshellcmdflag
to use an interactive shell):vim[grep] /<pattern>/ <files>
: internal grep tool (puts results in quickfix):make <target>
: builds the project and outputs errors to quickfix (plugin to make it async):%s/<pattern//n>
: count number of occurences of:%g/<pattern>/<command>
: execute command on matching lines
Windows
CTRL-W o
: close all windows but the current oneCTRL-W q
: close current windowCTRL-W SHIFT-T
: move current window to new tabCTRL-W s
/CTRL-W v
: split window horizontally/vertically
Recipes
:tabnew | r ! <shell_cmd>
: Runsand puts its output in a new tab :tabnew | set buftype=nowrite | set syntax=diff | r !git diff
: Shows repo changes in new tab (with highlighting)sil[ent] gr[ep] <options> <pattern> <files>
: use normal gnu grep (cfgrepprg
). Useful for recursive options
Misc
g CTRL-G
: display buffer stats (lines, words …)- Set specific options per folder using local .vimrc
"ayiw
: yank (i for inside) word under cursor into register a
Command mode shortcuts
CTRL-R CTRL-W
: paste word under cursor into command line
Registers
- Do not use numbers or “ (default register), they will be overwritten automatically on some cases.
- You can move registers with
:let @a=@"
(saves the default register to a)
Ranges
%
: all.
: current line.,$
: from current until end1,.+1
: from the start to the next line after the current one
Pattern syntax
Depends on magic
value. Most used features are listed below.
‘magic’ | ‘nomagic’ | ||
---|---|---|---|
$,^ |
$,^ |
matches end/start of line | |
. |
\. |
matches any character | |
* |
\* |
any number of the previous atom | |
\(\) |
\(\) |
grouping into an atom | |
\| |
\| |
separating alternatives (normal | is used to concatenate commands) |
\{ |
{ |
number of pattern occurences | |
\s,\w,\W,\d |
\s,\w,\W,\d |
Common character classes |