I'm trying to find a good way to remap control+U in insert-mode
so that it begins an undo-block. There are times when type
control+U in insert-mode and it doesn't do what I intend, or I
want to undo it, only to find that an "u"ndo doesn't solve the
problem. I know that transitioning out of insert-mode (via <esc>
or <c-o>) will mark a point in the undo-stack.
>
> I am not sure I understand you right, but do you mean something
> like <c-g>u in insert mode ? (:help i_CTRL-G_u):
>
> :imap <c-u> <c-g>u
Yes, precisely! Thanks! Or rather, it's the piece I was missing:
:inoremap <c-u> <c-g>u<c-u>
As usual, Vim had the functionality, I just couldn't figure out
how to find it in the help. It didn't help that the help only
provides the one line you quote for the entirety of assistance on
the matter. The whole i_CTRL-G family of commands are new to me.
More stuff to learn. ;)
I'm still not 100% sure why I got this craziness:
inoremap <c-u> <c-o><nop><c-u>
This gives me a crazy
"E486: Pattern not found: insert"
which, I haven't searched for the word "insert" so this one makes
me scratch my head. Bug perhaps? Vim-internals showing through?
to try and reproduce something similar, I did
vim -u NONE
:set nocp
:inoremap <c-u> <c-o><Nop><c-u>
inserted some text and hit control+U. This time I got "E35: No
previous regular expression".
I suspect that the "<Nop>" isn't getting interpreted as the "do
nothing" operator as described at
:help <nop>
but rather is being interpreted as "less-than, en, oh, pee,
greater-than" and the "en" portion of it is trying to look for
the last regexp. I'm not sure how it thought I looked for
"insert" previously, as I don't consciously remember searching
for such text this morning. The docs on <nop> don't seem to
detail that the only permissible context is a stand-alone <rhs>
of a mapping.
Ah well. At least I have the CTRL-G_u functionality to solve the
problem. Thanks again,
-tim