vim key mapping to existing key - vim

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.

Related

Vim simple mapping

I started using Vim recently, just installed NERDTree (a plugin to navigate files).
The command to access that plugin is :NERDTree so I though it's a good idea to start learning mappings by assigning one to that command.
So I added to my .vimrc file the following line: map :nt :NERDTree - but when I type :nt in a vim file (even after restarting) I receive the following error message: not an editor command: nt
I also tried to add the mapping directly while editing a file by typing :map :nt :NERDTree but it returned the same error when I tried to use the command.
I checked that answer:What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in vim?, so it seems to me that :map (opposed to noremap etc.) is the good command for that.
The plugin works fine when typing the original command.
What am I doing wrong? (sorry for the noob question)
:NERDTree is a command, not a mapping, so there's no reason for creating a recursive mapping, here.
:map is too overreaching. You should use :<mode>map (for recursive mappings) or :<mode>noremap (for nn-recursive mappings).
You are missing a <CR> at the end of your mapping to tell Vim to actually execute the :NERDTree command.
In this specific case, the right mapping would be:
nnoremap :tn :NERDTree<CR>
But mapping something to :<anything> is not a good idea because it will introduce a timeout whenever you try to execute an Ex command. This means that you need to find another combo. Why not <Space>n?
nnoremap <Space>n :NERDTree<CR>
With the mapping that you have, it will be require multiple keystroke. Will it be okay for you to use a single key like F2?
nnoremap <F2> :NERDTreeToggle<CR>
This will toggle open/close NERDTree upon pressing F2 and save you some key stroke.
Here
you can figure out, how vim's mapping work and look like ;). Don't forget to source your new .vimrc before using.

How to imap <Space> in vim

I am writing a vim script which may need to map the key to trigger a function, but it looks like whatever I write in the imap command, the mapping is not worked.
For testing purpose , I set map the to like:
imap <Space> <Esc>
So I should escape from the insert mode when I press a space.But it seems not working... Is it possible to imap in vim? If not, I will find another way to work around.
It's so strange to answer my own question , but I found a solution after all. mapping-enter-key-in-vim In this question, the answer is
inoremap <buffer> <Space> <esc>
Another problem is that AutoPairs is overriding setting.... So my setting is not working.

VIM, mapping, Why doesnt nmap <Alt><Right> <C-w><Right> work?

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>

What does <unique> mean in vim?

In my previous question I tried to "rewrite" default mapping of Netrw's NetrwRefresh command. The default mapping was <c-l> and I wanted to free it for different purpose. Suggested solution was the following:
nmap <unique> <c-r> <Plug>NetrwRefresh
" from now on I can use <c-l> for whatever I want
Everything is fine, but when I try to change <c-r> to <leader>xx every time I get this error:
Whatever I place after <leader> the error always occur. I tried to remove <unique> and I get the result. So the question is: what the <unique> is intended for?
As always, Vim's :help command should point you in the right direction. From :help unique, is documented:
If the first argument to one of these commands is "" and it is used to define a new mapping or abbreviation, the command will fail if the mapping or abbreviation already exists
So Vim is telling you that a mapping already exists for <leader>xx and refuses to overwrite it. To determine what is already using <leader>xx in your setup, you may view all mappings:
:map
It seems unusual and somewhat unlikely that anything you try following <leader> is already in use, so examining the output from :map should reveal some available combinations.

How to debug vim mapping overlaps?

In general how to debug and solve key bindings overlapping?
I had this problem..
Recently I add vim-latex plugin to my vim dir.
After that I noticed that my ctrl-j bind is overlapped by vim-latex/plugin/imaps.vim and lost a lot of time until solved that.
By the way: there is a bug in imaps.vim i think, because there is written " map only if there is no mapping already" and my example shows opposite.
You can get fine-grained info from the :map command:
To show only mappings relevant to a particular key (in this case ctrl-J):
:map <c-j>
or, better, to show mappings for particular key as well as the script where the mapping was set:
:verbose map <c-j>
It is the addition to other people’s answers, not the answer itself.
By the way: there is a bug in imaps.vim i think, because there is written " map only if there is no mapping already" and my example shows opposite.
You are mistaking what «mapping» here means. If you take a look at the code of imaps.vim you’ll see that it won’t create a mapping if there is a mapping to <Plug>IMAP_JumpForward ({rhs}), not if there is a <C-j> mapping ({lhs}). Thus you should use
nnoremap <SID>I_won’t_ever_type_this <Plug>IMAP_JumpForward
in order to disable <C-j> remapping if you don’t need it (of course you could replace <SID>... part with something more meaningful if you do want to use this functionality).
:map
Shows a list of your current maps.

Resources