How do I set a named mark so I can jump back to an exact position later?
Answer
m{a-z}
Explanation
Vim's mark system lets you bookmark positions in a buffer and return to them instantly. m{letter} sets a mark at the current cursor position; ' (single quote) + letter jumps to the line, and ` (backtick) + letter jumps to the exact line and column.
How it works
ma— set markaat the current position'a— jump to the line where markawas set (first non-blank character)`a— jump to the exact line and column of marka- Lowercase marks
a–zare buffer-local (each buffer has its own set) - Uppercase marks
A–Zare global — they persist across files and Vim sessions (saved in.viminfo/shada) :marksdisplays all currently set marks:delmarks adeletes marka;:delmarks!clears all lowercase marks
Example
Mark your position before a large search:
ma " mark current position as 'a'
/somePattern
" ... navigate around ...
'a " jump back to the marked line
Or use a global mark to jump between files:
mA " set global mark 'A' in config.vim
" open another file...
'A " jump back to config.vim at the marked line
Tips
- Vim automatically sets special marks:
`.(last change),`"(last exit position),'[and'](last yanked/changed region) ''(double single-quote) jumps to the last jump position — a quick way to toggle between two locations- In a macro, set a mark before the operation and jump back to it at the end to reliably reposition the cursor
:marks abcABClists only those specific marks