In Vim, if I issue a jump command, e.g. G
, then I can put the cursor back where it was before the jump by using Ctrl-o
. However, Ctrl-o
would not put my cursor back to the previous spot if I issued a movement command like 40j
or Ctrl-f
, since they don't alter the jump list. Is there a command which will undo movements such as those?
To be clear, I'm not looking for a "manual" answer, such as 40k
gets you back from 40j
, since such a command is not generically applicable in the way that Ctrl-o
works.
Also, if no built-in command does this, then does any plugin do it?
Ctrl+f will search within the file ctrl+shift+f will search in all the files in the folder tree.
Remember, yo undo a change in Vim / Vi use the command u , and to redo a change which was undone use Ctrl-R .
To cancel a running command in Vim, press Ctrl+C .
2 Answers. Show activity on this post. You have only 1 level of undo if you are in Vi compatible mode. You are missing out on a number of features by being in 'compatible' mode.
You can override the default motions to provide for that, like this:
" j, k 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'
There's also the reljump plugin, which implements the same.
However, be careful, because overdoing this will reduce the usefulness of the jump list. For that reason, I would advise against changing Ctrl-F / Ctrl-B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With