I'm moving from Emacs to Neovim and still like a few things in Emacs functionality.

One of the things I find I would like is to stay in insert mode when I'm typing large documents (instead of constantly going back and forth).

One of the things I have remapped is:

inoremap <C-/> <C-\><C-o>:u<cr>

which reverses everything one by one when C-/ is pressed.

However, I want to only have this go on for a second unless there has been a C-/ pressed in that time interval, otherwise I want to undo the (undone) change that I have made. Is there a way to do this?


  • I’m confused: don’t u and <C-r> handle undo and redo from Normal mode? What’s missing?
    – D. Ben Knoble
    Dec 26, 2023 at 21:54

1 Answer 1


Here is an attempt of mapping:

function! InsertUndo()
  let t = reltimefloat(reltime())
  if exists('g:lastundo') && (t - g:lastundo) < 1
    let ret = "\<C-\>\<C-o>\<C-r>"
    let ret = "\<C-\>\<C-o>u"
  let g:lastundo = t
  return ret

inoremap <expr> <C-/> InsertUndo()

It undo the last change if no undo have been attempt in the last second otherwise it redo the last undone change.

Remark: That being said the general recommendation of Vim experts is to leave the insert mode often and do most of the operations in normal mode. But Vim is very configurable and you can create your own usage far away from Vim "philosophy" (although it is not recommended).

  • Thank you for this, it is really a learning experience. Thank you for facilitating learning in a heterodox environment. Dec 27, 2023 at 5:00
  • Thanks for your feedback and Welcome to Vim :-) Dec 27, 2023 at 6:12

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.