neuromancer
neuromancer

Reputation: 55579

Binding special keys as vim shortcuts

My keyboard has extra hotkeys like "Back" and "Forward" that work in a web browser. I would like to use these types of keys as hotkeys in vim. How can I find out what vim sees these keys as so that they can be used as hotkeys in vim?

Upvotes: 1

Views: 1148

Answers (1)

Andrew Langman
Andrew Langman

Reputation: 1771

Go to the command line, type control-k (you'll get a question mark on the command line), and then hit the key you're interested in. The question mark will be replaced with Vim's definition of what it receives.

In my experience, you won't get a response for every odd key. Also, for some keys you'll get a different response in gVim versus console Vim. I'm stuck on a Windows machine at work, but I sometimes SSH to our Linux server and use Vim there. In both gVim on Windows and console Vim on a Linux box, Vim says that the function key F7 is sending:

<F7>

And on Windows, when I type shift-F7, Vim reports:

<S-F7>

That all makes sense. But when I type shift-F7 on the console, it reports:

[31~

And after a lot of digging around, I found that to actually use the above value in a map I had to write it as:

<Esc>[31~

So my mapping to make F7 increment numbers and shift-F7 decrement numbers looks odd in console Vim:

map <F7> <C-A>
map <Esc>[31~ <C-X>

But it does work.

Upvotes: 3

Related Questions