new to vim, recently came across mapping keyboards issues, what get on google and stackoverflow is only something like this map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR> and map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>, then I searched Vim documentation: map http://vimdoc.sourceforge.net/htmldoc/intro.html#<>, but what it also does not explains the syntax, the meanning of the symbols, can someone suggest some reference materials for this? Thanks very much!
A mapping like the ones you mentioned has three parts:
the type of mapping (map/nmap/imap/vmap/... and the corresponding noremap versions). This determines in what modes the mapping is active. map means normal mode, visual mode and operator-pending mode. When using noremap/nnoremap/... the mapping is made with respect to Vims standard keybindings, otherwise the mappings can themselves call mappings.
The key(s) to bind. This can be a normal key, a control character like <C-\>, or a sequence of keys.
a key sequence to map to.
In your first case, you map the key <C-\> (control-backspace) to :tab split<CR>:exec("tag ".expand("<cword>"))<CR> in normal, visual, and operator-pending mode.
Related
The effect that I would like is to remove all key mappings/bindings from vim such that I can then only specify the bindings I use and build from there.
What is the best way to disable everything so that I can configure a whitelist of my own?
The only way to do what you want is to map every built-in command to :help <Nop> in all relevant modes:
nnoremap a <Nop>
xnoremap a <Nop>
...
and then to create your own custom mappings:
nnnoremap a <do something>
Note that Vim's commands are not implemented as mappings. The above overrides every key combination with a new empty mapping, essentially disabling it, and then creates your own custom mappings.
But Vim's default commands a) are plenty, and b) very expressive so why bother? What value, exactly, are you expecting to get out of this? Why would you want to remove features from a tool whose primary selling point is that it has so many features?
When you define a new key mapping with noremap, or nnoremap inoremap, the default key mappings are overwritten.
Total vim newbie here, is there a way to map two consecutive <Shift> to execute :FZF? I try the following config in .vimrc but no luck
nmap <S><S> :FZF<Enter>
Unfortunately you can't atleast not without some serious hacking. To quote from the vim wiki
Note that you cannot map the Shift or Alt or Ctrl keys alone as they
are key modifiers. You have to combine these key modifiers with other
keys to create a map.
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_2)
Also i'd recommend you use nnoremap rather than plain nmap, unless you explicitly want your map to be recursive.
On a personal note i use the following mapping for :FZF which is basically a space followed by a 'f' in normal mode. I find it quite nice.
nnoremap <Leader>f :FZF
Happy Vimming.
How can i use ALT key in key mapping?
And how can i make double key commands? for example i tried
<Alt-Right> <C-w><Right>
and it didnt work either.
And as far as i know, some keys are bad to be used for mapping in VIM, Space key for example. if possible, write also please keys which usually do not work in key mapping in Vim.
This should work in a graphical Vim (GVim, MacVim):
nnoremap <M-Right> <C-w><Right>
"Alt" is a new invention, which Vim doesn't know - it knows about "Meta", a key that once existed, and keeps calling the newfangled invention by the old key's name.
However, terminal is trickier, as Alt-Right is typically bound to some key sequence that is useful in Terminal, like Escf (move one word right); you can see what it is in Vim by preceding it by Ctrl-V: nnoremapCtrl-VAlt-Right<C-w><Right>, which will probably come out as
nnoremap ^[f <C-w><Right>
i am trying to figure out vim key bindings... what key does correspond to? or more generally how do I read vim key bindings? I looked at the VIM documentation but it was not very clear.
It's Ctrl+C. See :help key-notation.
You can use #romainl's answer:help key-notation to find the notation of each modifier keys.
And you can use below commands to see the current mappings in your vim:
:nmap Show key maps for normal mode
:vmap Show key maps for visual mode
:imap Show key maps for insert mode
:map Show all the key maps
I am trying to map my space key to make the Vim go into insert mode from normal mode.
The reason I want to do this is because sometimes I forget that I'm in normal mode and start typing as if I'm in insert mode. When I press the space key in between or even in the start of the page, it moves down and something or the other types due to the possibility of a press a or i in what I just typed.
So to avoid this I want to map my space key to insert mode from normal mode as we press i to do so.
I tried the following:
map space :i
map <space> :i
But these doesnt seem to work.
You're mixing up the modes in your mappings; that's an important concept in Vim. Though there's a :startinsert Ex command in Vim (where your mapping would indeed start with a :), it's more straightforward to use the normal mode i command:
:nnoremap <Space> i
You only want a normal mode mapping here, so :nmap, not :map; cp. :help map-modes. And see :help key-notation for why it's written <Space>.
Finally: You should always use :noremap; it makes the mapping immune to remapping and recursion.
strange requirement, but, you have your reason. :)
try this line out:
nnoremap <space> i