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>
Related
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.
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.
I'm working on mappings in vim and ran into a problem. I can map to <Up>, <Down>, <Left>, and <Right>, and I can map to <S-Left> and <S-Right>, but I can't map to <S-Up> and <S-Down>. In other words
:nmap <S-Right> l
works, and so does
:nmap <Up> l
but
:nmap <S-Up> l
doesn't.
Maybe SO will know the answer to this problem, in which case I'll change the question title to be more specific. But failing that, I'd like commands I can use to diagnose what's failing where.
(if I broke your up key with the above command, type :unmap <Up>)
The issue probably is with your terminal [settings].
What you can do to troubleshoot is trying to literally insert the keys received by Vim. In insert mode, type <C-V> followed by the (shifted) cursor key. For me (gnome-terminal with TERM=gnome-256color), I get these distinct values (so shifted cursor keys all work for me, yay):
" Up, S-Up, Down, S-Down
^[OA ^[[1;2A ^[OB ^[[1;2B
" Left, S-Left, Right, S-Right
^[OD ^[[1;2D ^[OC ^[[1;2C
If you see the same values for shifted and unshifted keys, your terminal doesn't distinguish between them, so Vim cannot, neither. The next step would then be to check your terminal settings / use a different terminal.
I am trying to map a key combination to an existing key combination and added this in .vimrc file:
noremap <C-A> <C-TAB>
what I want to do is to let CTRLA does exactly what CTRLTab does in my Vim environment. But it is not working. Could someone point out what I did wrongly, thanks.
The "nore" on the front stands for "no recurse", i.e. it won't "recurse" to invoke C-TAB as a command. I believe just map <C-A> <C-TAB> should work, if I grok the question (and vim...). See :help map-commands for some useful explanation.
I'm not sure whether you really want to do this though, as it could interfere with other commands.
I like to use hlsearch but I hate to keep everything highlighted after searching, to solve this problem I could simply use :nohlsearch or an abbreviation of it but that is still to much effort so I decided to try to do that on pressing escape. What I came up with is:
nnoremap <ESC> :nohlsearch<CR>
This works exactly as I want it to in GVim which I usually use for development but it does not work in vim.
If I search something in vim, press escape to deactivate the highlighting and use one of the arrow keys to navigate vim goes directly into insert mode and inserts a character on a new line.
As I never really came around to using h, j, k and l for navigation this is really annoying and I would like to know how I can make vim behave like gvim.
If you need more information you can find my entire vim configuration here.
Your problem is that when you press <Up> terminal sends something like <Esc>OA (you will see it if you type <C-v><Up> in insert mode) which is remapped to :nohlsearch<CR>OA. I do not know any solution except not mapping a single <Esc>, try either mapping to double <Esc>.
I created this map to disable search when press double <Esc>
nnoremap <silent> <Esc><Esc> :let #/ = ""<CR>
is :noh still too much work?
EDIT: I don't know about you, but I personally think :noh is easier than pressing Esc key, since I can press all the buttons without stretching my pinky too far (which is why I think the default mapping of Esc for going back to Command Mode from Insert Mode is a bit unfortunate). If you really use the :nohlsearch that much, you probably should remap it to something you can reach from the Home Area (i.e. regular letters, or numbers, or perhaps Ctrl-letters).
Anyway, typing the exact command you give works in my vim (on gnome-terminal). Are you sure you put the rule in .vimrc file, instead of .gvimrc? No luck after restarting vim? Try :source /path/to/config/file and see if that makes it to work.