I'm using Neovim on Ubuntu 18.04 LTS.

If possible, I would like the solution to work both in insert mode and command mode.

1 Answer 1


Key mapping is introduced in chapter 5 of the user manual: :help 05.3, and this is elaborated upon at :help 40.1.

You can use the following for normal mode:

nnoremap <C-Z> u
nnoremap <C-Y> <C-R>

For insert mode, you still need to run a normal mode command. You can include <Esc> in mappings to leave insert mode, but in this case you can also use <C-O> to run a single normal mode command while remaining in insert mode (See :help i_CTRL-O):

inoremap <C-Z> <C-O>u
inoremap <C-Y> <C-O><C-R>

For more details, see :help mapping.

  • Ha! You were faster @Rich . But what exactely will be the effect of the map in insert mode, without delimiting the undo history by exiting insert mode? :/
    – lsrdg
    Commented May 4, 2018 at 8:27
  • @lsrdg The first time you press it, it will undo the current insert. Subsequent presses undo previous edits.
    – Rich
    Commented May 4, 2018 at 8:29
  • Thanks and sorry, I commented while your answer consisted of only the mappings. (:
    – lsrdg
    Commented May 4, 2018 at 8:31
  • @lsrdg No worries! I think it's a legitimate question even after my edits. I wasn't sure what it would do until I tried it!
    – Rich
    Commented May 4, 2018 at 8:37
  • 1
    @DavidBenKnoble Good question! I only tested in the GUI, but I suspect job control would kick in before Vim gets a change to see the mapping in the terminal.
    – Rich
    Commented May 4, 2018 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.