Skip to main content
A bit more verbose
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

AddPutting aside mappings for a moment, what do we do when we're manually entering commands and find a range on the command line that we don't want? Hit Backspace five times? Well...yes...that's one possibility but there's something better than that:

                                                    c_CTRL-U
CTRL-U      Remove all characters between the cursor position and
            the beginning of the line. ...

Since a mapping is essentially the same as the equivalent manual command we just need to translate Ctrl+U to something that works in Vimscript. That would be the equivalent keycode <C-U> to.

So add <C-U> at the beginning of your mapping right after the opening :. For example:

vnoremap XX,a :<C-U>silent! ..etc..

ThisThat will clear whatever mayany text that happens to currently be on the command line.

See :h c_CTRL-U before your command(s) are applied.

Add <C-U> to the beginning of your mapping right after the opening :. For example:

vnoremap XX :<C-U>silent! ..etc..

This will clear whatever may currently be on the command line.

See :h c_CTRL-U.

Putting aside mappings for a moment, what do we do when we're manually entering commands and find a range on the command line that we don't want? Hit Backspace five times? Well...yes...that's one possibility but there's something better than that:

                                                    c_CTRL-U
CTRL-U      Remove all characters between the cursor position and
            the beginning of the line. ...

Since a mapping is essentially the same as the equivalent manual command we just need to translate Ctrl+U to something that works in Vimscript. That would be the equivalent keycode <C-U>.

So add <C-U> at the beginning of your mapping right after the opening :. For example:

vnoremap ,a :<C-U>silent! ..etc..

That will clear any text that happens to currently be on the command line before your command(s) are applied.

Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

Add <C-U> to the beginning of your mapping right after the opening :. For example:

vnoremap XX :<C-U>silent! ..etc..

This will clear whatever may currently be on the command line.

See :h c_CTRL-U.