1

in normal mode Ctrl+e scrolls the buffer itself. from :h CTRL-E

CTRL-E ...........................................* Scroll window *
[count] lines downwards in the buffer.

I would like to remap that so when I press Ctrl+e vim performs 3 x Ctrl+e.
I've tried

  • map <Ctrl-e> 3<Ctrl-e>
  • nnoremap <Ctrl-e> 3<Ctrl-e>
  • nnoremap ^E 3^E

but these have no effect, how can I perform this mapping?

3
  • 1
    :help key-notation
    – romainl
    May 25, 2016 at 8:16
  • @romainl I was looking for that exact section in the documentation when I asked the question. I remember seeing it but couldn't remember how to get to it! May 25, 2016 at 8:25
  • I knew it had ctrl-k but when I tried :helpgrep ctrl-k I got nothing. Helpgrep is case sensitive so I should have used :helpgrep ctrl-k\c May 25, 2016 at 8:45

2 Answers 2

4

The reason why

:nnoreamp ^E 3^E

Doesn't work is because ^E is two separate characters. You can tell because you have to hit the arrow keys twice to move backwards past it. So you are really remapping ^ E to 3 ^ E, which is probably not what you want to do, especially since ^ doesn't take a number argument.

When you use a digraph, this is displayed as two characters, but it is a single character, which you can tell because backspace and arrow keys treat it as a single character. The other way you can tell is because vim will (probably) display it as a different color. For me, this digraph appears blue, but it might be different for you depending on your setup.

The answer you came up with works but it isn't the ideal way or the idiomatic way. A better way of entering a digraph is with <C-v>, rather than <C-k>. With <C-k> you have to hit ctrl+e twice, but if you were to use <C-v> you could just hit ctrl+e one time and it would work. So that would look like

:nnoremap<space><C-v><C-e><space>3<C-v><C-e>

Which is a little easier than what you were doing. An even better way (IMO) is to use an ASCII literal, rather then a digraph. I prefer this method since:

  • It keeps your .vimrc tidier.

  • It is easier to understand what is pressed vs what is sent to vim.

  • It's more readable.

  • It avoids nasty unicode unprintables.

You were close with your initial try of

:nnoremap <Ctrl-e> 3<Ctrl-e>

You just got one minor detail wrong. <Ctrl-e> does not describe any keystroke that vim can understand. You should have written

:nnoremap <C-e> 3<C-e>
5
  • nice explanation, thanks. the ascii literal sounds nice as it might be something a bit more non-vim specific. what would be an example of an ascii literal? May 25, 2016 at 5:04
  • 1
    @the_velour_fog No, using <C-v> is vim specific. It's just how vim handles keys with modifiers. There's also <M-v> (meta + v, usually alt) and <S-v> (shift + v). In other languages, it would probably be a hex code corresponding to the ascii table, although it varies from language to language.
    – DJMcMayhem
    May 25, 2016 at 5:08
  • interesting, I just entered the ^E digraph character into a file using vim, then opened the file with hexedit. the character in hex is 05 , from the ascii table it is called ENQ where this explains that ENQ is an old way of referencing Ctrl-e May 25, 2016 at 5:24
  • 1
    If you find that interesting, you'd also find it interesting that ctrl+ a, b, c, ... is 01, 02, 03, 04 .... Also, if you take any valid key and do it again but with alt down, it adds 128 (hex 80) to the ASCII value.
    – DJMcMayhem
    May 25, 2016 at 5:30
  • nice, with Ctrl + a,b,c (I need to hit C-b twice because Im running tmux) I get that result. But if I open a file in vim as UTF-8 and press Ctrl-v,then alt + a I get two characters. in vim it looks like ^[ and then a normal a. In hexedit its 1B and 61 . from ascii table, ESC and letter a, weird... May 25, 2016 at 5:45
1

in the end this worked

  • hit :nnoremap
    • enter command line mode
  • hit <space>
    • to put a space between nnoremap and control char about to come
  • hit <C-k>
    • to enter "digraph"? mode see more info see: :h c_CTRL_k
  • enter Ctrl-e twice to generate special non-printed character which appears as ^E but if you manually type ^E in your mapping it doesn't seem to work?

at this point the command line or buffer looks like (note: the digraph generated character sequences appear a different color to normal text and they are treated as a single character not ^ and E.)

:nnoremap ^E

add a 3 and another digraph generated ^E till command line or buffer looks like

:nnoremap ^E 3^E

Your Answer

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

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