0

I am trying to remap the line-completion command (^X^L) to the simpler ^L (or Ctrl-L, or <C-L>). VIM's help (see :h ins-completion) suggests the following :

:inoremap ^L ^X^L

I tried adding this to my .vimrc, but so far pressing Ctrl-L in insert mode only inserts "^L" at the cursor's position.

1
  • 2
    Try :inoremap <C-L> <C-x><C-L>
    – D. Ben Knoble
    Commented Sep 29, 2022 at 21:35

2 Answers 2

3

Those keys are intended to be control characters, which are some of the special keys in Vim. As you have mentioned, ^X, ^L, are meant to represent Ctrl-x and Ctrl-l respectively. *

There is an alternative angle bracket notation, which is documented in :h key-notation and :h <>. This notation is used in vim documentation, and can also be used in mappings.

In mappings, these can be typed as-is, without the need to press <C-v> to specify control characters. Thus a recommended alternative is

inoremap <C-L> <C-X><C-L>

*these special keys have to be entered with Ctrl-v Ctrl-x, Ctrl-v Ctrl-l, which will be displayed in vim as ^X ^L, typically with a different highlighting. In the image below, the first line displays control characters, while the second line shows literal characters, such as a literal caret (^).

enter image description here

0

I was "naively" copy-pasting the remapping line, which did not properly input the keys as wanted.

To properly input the mapping line in my .vimrc, I had to use the "insert control-V" (see :h i_CTRL-V), typing <C-V> <C-X> to input the proper ^X, and typing <C-V><C-L> to insert the proper ^L.

I don't really understand how that works, I was simply lucky enough to have encountered a similar problem earlier and remembered there was a command to verify what was "actually" inputted.

I won't accept my answer as the right one, just in case anyone is brave enough to try and explain the solution better; I will however leave it in case someone wants the quick and dirty solution.

1
  • 1
    You can use literal escape sequences by pressing control+v and then the key, but the common notation is to write <C-l>. The documentation in :help ins-completion is a bit odd here, and probably quite old. Commented Sep 30, 2022 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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