I'm new to vim and install that in windows 10.

I write this instructions in Vim then in normal mode pressed u and all the instructions disappeared.

console.log(899) hello you can write some simple Javascript instructions here....

But when I use VsCode and press Ctrl-z all the instructions will not disappear. VsCode deletes word by word where Vim deletes all the things.

How can I set this behavior in Vim?

  • u is to undo the last action in a whole. Here, the action was to put a full line (not a word.) The undo will work as you expect if you insert one word a time… However, you can delete a word the cursor is on with diw
    – gildux
    Jan 3 at 12:19

2 Answers 2


The undo action is per-line if you write a bunch of lines in insert-mode. This is natural as most languages use 1 statement per line (usally).

To override this behavior while in insert mode use Ctrl-g u to manually add an undo point.

  • Actually, if you type i<multiple lines of text><esc>, then u removes all text, since the action was a single insert.
    – D. Ben Knoble
    Jan 3 at 14:30
  • I don't get that behavior if there are line-breaks in the insert action. I can see each line in my undoTree. Jan 4 at 14:21
  • 1
    You might have a mapping on <enter> in insert-mode; try vim --clean
    – D. Ben Knoble
    Jan 4 at 21:02
  • @D.BenKnoble You are right. vim --clean gives the behavior as you said. Must be something in my config/plugin that changed that behavior. Jan 26 at 12:26
  • Thanks, It works for me. Feb 20 at 5:42

One way to get à behavior to want you want is to have the following mapping:

inoremap <space> <C-g>u<space>

It create a new undo operation each time you insert a space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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