What possible downsides are there to using <C-g>u on a regular basis to break the undo chain in small chunks, e.g. after every line-break or after every sentence? Has someone experiences with this?

  • 4
    Related reading: Drew Neil’s book Practical Vim has a chapter where he discusses “pausing with your paintbrush off the canvas”—basically, hit escape any time you pause. The habit is worth it.
    – D. Ben Knoble
    Apr 3 '19 at 17:04
  • I thought of a script or a mapping, like :imap <Space> <Space><CTRL>gu or so...
    – Thomas D
    Apr 3 '19 at 17:15
  • 2
    Yes some people do this after entering punctuation or pressing enter in insert mode. It's basically a personal preference. Apr 3 '19 at 20:48
  • Open :h insert.txt and search for inoremap, you'll get some examples.
    – klaus
    Apr 4 '19 at 3:53

For markdown I have the following mappings in ~/.vim/after/ftplugin/markdown.vim:

" Break undo sequence at punctuation marks
inoremap <buffer> . .<c-g>u
inoremap <buffer> ! !<c-g>u 
inoremap <buffer> ? ?<c-g>u
inoremap <buffer> , ,<c-g>u

I don't think that this makes a difference in my workflow, because I seldom use undo on text that I just typed. It is more likely that I undo a formatting, deletion or copy command.

Anyway, I don't see any negative impact from this.

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