Question: Is there something which is works same as i_CTRL-G_u, but for normal mode?
This would be useful in mappings (like nnoremap
), because (I think, but fixme) in normal mode, if you are just typing commands (vs. a sequence mapped to a single key), then each command counts as a separate undo block.
Case in point: I'm trying to solve this exercise, from Learn Vimscript the Hard Way.
This is what I came up with, and it seems to work:
:nnoremap <leader>d ddi<C-G>u<esc>dd
While this works, it seems a bit hackish, going into insert mode just to break the undo sequence, so I was wondering if it is possible without going into insert mode.
Of course, I already tried the following variant, but all it does is deleting a single line, so it seems that the <C-G>
part kind of ends the sequence:
:nnoremap <leader>d dd<C-G>udd
nnoremap <leader>d dd@=execute('let &ul = &ul')[-1]<cr>dd
. But technically, it still temporarily leaves normal mode to enter the command-line (the expression one). See vi.stackexchange.com/a/26475/17449.