For example, I'm browsing the 700th line, and I typed ":456" to jump to the 456th line. Now I want to quickly return to the 700th line. Is there any shortcut key instead of typing ":700".
The jumplist (see :help jumplist) can be navigated with
Ctrl-o, to go back to
line 700 (and
Ctrl-i would take you back to line 456 again).
If you want to be able to do this with relative jumps (i.e. after typing
to go seven lines down, use
Ctrl-o to return to where you before the relative
jump), you can use following two remaps in your .vimrc:
" store relative line number jumps in the jumplist. nnoremap <expr> k (v:count > 1 ? "m'" . v:count : '') . 'k' nnoremap <expr> j (v:count > 1 ? "m'" . v:count : '') . 'j'
Seems remiss1 to not mention what some would consider the fastest way to jump back to the previous line:
'', i.e. just double-tap apostrophe. The nice thing is that you can bounce back and forth between two lines with the same command.
A couple things to be aware of:
- This takes you to the first non-blank character of the previous line (as all jump-to-mark commands starting with
'do). To return to the same line and column double-tap back-tick (
ctrl-othis only works after motions that are registered in the jumplist.
1 Just to be clear I mean remiss on the part of the community and not @mattb specifically!