Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Windows key be mapped in Vim?

Using Windows key as Meta is very useful in Emacs, is there the way to do it in Vim?

like image 962
Alexey Romanov Avatar asked Nov 29 '08 10:11

Alexey Romanov


People also ask

How do I map a key to a vim command?

To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.

Does vim allow for custom key bindings?

I was delighted to learn that you can have your own key mappings in Vim. It is documented very well in the vim help section.

How do you check if a key is mapped in vim?

Use :map! and :map for manually set keys and :help 'char(-combination)' to find out which keys are already mapped in vim out-of-the-box(/out of your specific compiling options).

How do I Unmap a key in vim?

On vim , command-mode keys can be mapped through the ex command :map <key> <macro> and insert-mode keys can be mapped through :map! <key> <macro> . After mapped, the commands to remove the mapping from the command-mode keys and insert-mode keys are unmap <key> and unmap!


2 Answers

You definitely can, even in terminal, although you have to use it as a meta key (I found no way to use it on its own).

Edit your .vimrc file with vim. Say you want to remap Win+q in normal mode to quit vim. Simply add your mapping and, when trying to indicate your shortcut, press Ctrl+V, then Win+q.

This will add something similar to ^X@sq to your file (but do not type it directly, the ^X is a special character).

In the end your line should look like:

nnoremap ^X@sq :q<CR>

Save and quit, launch vim again, and that's it.

Note: Ctrl+v in insert mode inserts followoing key/combination of keys literally. For more info try :help i_CTRL-V in vim.

like image 194
guest Avatar answered Sep 24 '22 00:09

guest


Sorry for answering so ancient question, but solution is really simple: it is impossible to use Win key in the terminal, but it is possible to use it with Gvim. Just pass it as modifier T. For example,

:nmap <T-F5> :q<cr> 

will map Win+F5 to :q command. But it is usable only under *nix.

like image 22
frp Avatar answered Sep 23 '22 00:09

frp