I'm using Vim on Ubuntu. When I press a function key in insert mode, the name of the key is inserted literally.

For example, if I'm in insert mode and I press Ctrl+F12, the following text is inserted <C-F12>. I have this key tied to a global shortcut key to trigger a Google search box. Furthermore, I can see no personal practical value to inserting the name of a function key into the file I'm editing.

  • How can I get Vim to not insert the name of a function key when a function key is pressed in insert mode?

Try this:

:map <C-F12> <nop>
:map! <C-F12> <nop>


:help :map
:help <nop>

However, I would assume that having a global shortcut key defined should "eat" the key events so Vim never sees them. Is it possible to tell your OS to behave that way for this binding? After all this probably only solves your problem for Vim, and not other applications.

  • Thanks. You are right. I guess I have two concerns. One is that the keyboard shortcut for the Google Quick search box on Ubuntu does not seem to take precedence over any shortcuts defined in the active window. Two, I'd like to disable all printing of function keys in insert mode in Vim. – Jeromy Anglim Sep 2 '11 at 9:05
  • You can add more mappings like the ones I've shown, but there's no real way to "wildcard" all function keys, so you'll have to do it individually. Vim does allow looping -- ":help :while" and you'll need to look at ":help :execute". – Heptite Sep 2 '11 at 17:34

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.