Useful Built-in Commands Worth Knowing
Quickfix and Location Lists
:vimgrep /pattern/ **/* " Search across files, populate quickfix
:copen " Open quickfix window
:cnext / :cprev " Navigate quickfix entries
Macros
Macros record a sequence of keystrokes and replay them:
q{register}— Start recording (e.g.,qato record into registera)- Perform your edits
q— Stop recording@{register}— Replay (e.g.,@a)@@— Replay last macro
Registers
Neovim has named registers for storing text:
| Register | Content |
|---|---|
"" | Default (last delete/yank) |
"0 | Last yank |
"1-"9 | Last 9 deletes |
"a-"z | Named registers (user-defined) |
"+ | System clipboard |
"* | Selection clipboard |
". | Last inserted text |
"% | Current file name |
": | Last Ex command |
To paste from a specific register: "ap (paste from register a).
Marks
Marks save cursor positions:
| Mark | Description |
|---|---|
ma | Set mark a at current position |
`a | Jump to exact position of mark a |
'a | Jump to line of mark a |
'' | Jump to position before last jump |
'. | Jump to position of last change |
Uppercase marks (mA) are global (work across files).
Other Useful Commands
| Command | Description |
|---|---|
ga | Show ASCII/Unicode value of character under cursor |
g Ctrl-g | Word count and position info |
Ctrl-a | Increment number under cursor |
Ctrl-x | Decrement number under cursor |
:!{cmd} | Run external shell command |
!!{cmd} | Filter current line through command |
:{range}!{cmd} | Filter range through command |
:r !{cmd} | Insert output of command below cursor |
:r {file} | Insert contents of file below cursor |
gq{motion} | Format (wrap) text |
Ctrl-o | Jump to older position (in Insert mode too) |
Ctrl-i | Jump to newer position |
Quick Reference Card
╔══════════════════════════════════════════════════════════════╗
║ NEOVIM QUICK REFERENCE ║
╠══════════════════════════════════════════════════════════════╣
║ NAVIGATION │ EDITING │ FILES ║
║ h j k l │ i a o O │ :w :q :wq ║
║ w b e │ dd yy │ :e {file} ║
║ 0 ^ $ │ p P │ :bn :bp ║
║ gg G │ u Ctrl-r │ :bd ║
║ Ctrl-u Ctrl-d │ x X │ ║
║ /pattern n N │ c m. t │ ║
║ │ . │ ║
╠═══════════════════╪═══════════════════╪═════════════════════╣
║ TEXT OBJECTS │ WINDOWS │ SEARCH/REPLACE ║
║ iw aw │ Ctrl-w s v │ :%s/old/new/g ║
║ i" a" │ Ctrl-w h j k l │ :%s/old/new/gc ║
║ i( i) │ Ctrl-w o │ ║
║ i{ i} │ Ctrl-w = │ ║
║ it at │ │ ║
║ ip ap │ │ ║
╠═══════════════════╪═══════════════════╪═════════════════════╣
║ VISUAL MODE │ TERMINAL │ MARKS & REGISTERS ║
║ v V Ctrl-v │ :term │ ma 'a ║
║ d y c > < │ Ctrl-\ Ctrl-N │ "ayy "ap ║
║ J K (move lines) │ │ "+y "+p ║
╚═══════════════════╧═══════════════════╧═════════════════════╝