vim - update file history more often

1

1

I was wondering if it is at all possible to have vim update its file history more often.

For example, if I got into insert mode, and type 20 lines of code, exit, and hit 'u', it undoes everything I had typed in.

Is there a way to make make these undos more granular without needing to pop in and out of insert mode all the time?

user235465

Posted 2015-05-14T16:41:30.330

Reputation:

Answers

1

You can explicitly create an additional undo point via <C-G>u in insert mode (:help i_CTRL-G_u).

Because that is tedious, I would recommend to build mappings that trigger this. For example, when completing a sentence:

inoremap . <C-g>u.

Or when inserting a register:

inoremap <C-r> <C-g>u<C-r>

You can also create one when pausing briefly, through an :autocmd:

autocmd CursorHoldI * call feedkeys("\<C-g>u", 'n')

Ingo Karkat

Posted 2015-05-14T16:41:30.330

Reputation: 19 513

What do you mean by inserting a register? Also, what does the n in the last command stand for? – None – 2015-05-14T19:10:25.857

You can paste from insert mode via <C-r>{register}, like "{register}p in normal mode. Since that can add a whole lot of text, an undo point is helpful. – Ingo Karkat – 2015-05-14T19:12:55.540

You can use the excellent :help to answer further questions: :help feedkeys() tells you that n means do not remap keys. – Ingo Karkat – 2015-05-14T19:13:47.103