Search code examples
vimrestoretext-cursor

vim: restore cursor to original position after <esc> from visual mode


When I'm in the visual mode and I decide to switch back to normal by pressing <esc> then I'd like to have the cursor back on the position where I entered the visual mode. How can it be achieved? E.g. something like:

vnoremap <esc> <esc>`<

but this will return always only to the beginning of the visual block.


Solution

  • Use mark. help mark

    nnoremap v m`v
    nnoremap V m`V
    nnoremap <C-v> m`<C-v>
    vnoremap <esc> <esc>``