I've got a tremendous keyboard: Microsoft Ergonomic keybord 4000. I'm also a intensive vim user on fedora.

The keyboard have a switch - FLock - that change the value for all - keys. Once switch they are seen by X as =Help =Undo =Redo and so on. But I didn't manage to map those keys to action in vim

xev before the switch:

state 0x2010, keycode 68 (keysym 0xffbf, F2), same_screen YES

xev after the switch:

state 0x2010, keycode 139 (keysym 0xff65, Undo), same_screen YES

So i tried a basic map in vim

:map u

But it didn't work. Any hints would be welcome!

  • I'm really not convinced that this is the right forum for this question - can you review our FAQ please. – Chopper3 Oct 13 '10 at 10:18
  • huch, I just rod the FAQ, you're right! I post the same subject on superuser. thanks, and sorry – user56986 Oct 13 '10 at 10:29

I suggest rebinding the extra keys at the X level using xmodmap so that instead of all the funky keycodes like "undo" they trigger standard F codes like "F20". This makes them much easier to bind in programs like terminal and hence vim.

You'll need something like this in your .xmodmaprc file:

keycode 139 = F13

Then the key becomes mappable in the usual way. From your .vimrc file, you can create a mapping like this:


The above works for bindings at the X level and will work for gvim, however key codes in terminal programs are a little different. You may need to tell vim about your new keycode so that it knows that the crazy thing sent by the terminal is an F13. You can do this by adding a line above your key map (see above) like this:

set <F13>=^[[25~

Of course what crazy code sequence you need there will vary depending on the key you are binding and your keyboard and your terminal, etc., but it's really easy to fill in. Using the terminal you usually use open your .vimrc with vim. Fill in the first part of the line set <F13>= then still in insert mode hit CTRL+v to insert a visual key code, then tap your new F key that you are trying to bind. Voilà, keycode found an inserted.

| improve this answer | |
  • Ok It work's in gvim but not in vim even when launched from the gnome-terminal. Is there any differences? I understand that it cannot work on true "console" – piir Oct 13 '10 at 12:15
  • You might need to tell vim how to interpret the keycodes the terminal passes along. Often these are not the same codes a normal x program would get (this is why gvim get's the codes). Use vim FROM YOUR TERMINAL to edit your .vimrc file. Right before your mapping line, add something like this: set <F13>=^[[25~ ...the keycode there is easy to fill in. Since you are already in your terminal using vim, just use the CTRL-v shortcut to insert a visual character, then hit your new F key and it will fill in the code it gets from the terminal. After that of course add your map/nmap macro. – Caleb Oct 13 '10 at 14:19
  • See edited answer above, I moved my notes from my comment to answer. – Caleb Oct 13 '10 at 14:27

There's a solution for vim I've found here using the following command:

set < F13>={C-v}{myspecialkey}

The key between { } must be typed as-is, then map the key with:

:map < F13> :undo<CR>
| improve this answer | |
  • Looks like we were both chasing this at the same time :) See my edited answer above. – Caleb Oct 13 '10 at 14:28

I have the same keyboard and under linux the "special" keys are not that useful as normal <FN>.).

Why not simply using the <FN> key mappings? Just do :nnoremap <F2> u and so on for other keys?

And I wonder, is not it easier to simply press u for undo? (Yeah, not in edit mode.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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