elynnaie
elynnaie

Reputation: 879

Remap Ctrl-D in vim

I want to remap another key combo, say CTRL-G, to function as CTRL-D does (note: not the same as S-Down/PageDown/CTRL-F).

What I have so far is:

nmap ^G :exe 'normal '.&scroll.'^E<CR>'

Bringing up my vim command mode and typing this in, it works perfectly. However, when I save my .vimrc and reload vim, I get the following error when pushing CTRL-G:

E114: Missing quote: '
E15: Invalid expression: 'normal '.&scroll.'

It seems to be stuck at not evaluating the ^E appropriately. However, I have been entirely unsuccessful in using or any other way of specifying CTRL-E. What am I missing here?

Upvotes: 4

Views: 4366

Answers (2)

Sven Koschnicke
Sven Koschnicke

Reputation: 6711

I think you can just write <C-E> for CTRL-E.

Upvotes: 2

Idan Arye
Idan Arye

Reputation: 12603

^G and ^E are special characters, and do not work well when you put them in the .vimrc. You need to use <C-g> and <C-e>, but since your Ctrl+E is placed inside a string, you need to escape it and write \<C-e>. You also need to use double quotes instead of single quotes - otherwise you can't do the escaping.

In other note - you should probably use nnoremap instead of nmap, so that if you remap <C-e> somewhere else, <C-g> will still behave like the original <C-e>.

Upvotes: 5

Related Questions