What does <unique> mean in vim? - 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.

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.

Can't remove mapping from VIM?

My vim configuration is adding some really annoying mappings for the sql filetype that conflict with my own.
I can verify it with the following command:
:imap <C-c>a
i <C-C>a *#<C-\><C-O>:call sqlcomplete#Map("syntax")<CR><C-X><C-O>
I want to remove it, but if any way I try it fails:
:unmap <C-C>a
E31: No such mapping
:iunmap <C-C>a
E31: No such mapping
I can clearly see that the mapping exist so why is it telling me that it doesn't?
The * in the :imap output gives it away: This is a buffer-local mapping, so in order to unmap it, you also need to specify the <buffer> attribute:
iunmap <buffer> <C-C>a
To undo the ftplugin mapping for all sql buffers, put this into ~/.vim/after/ftplugin/sql.vim.
Try inserting the <Ctrl-c> literally by first pressing Ctrl-v then Ctrl-c
It appears that in your first command for listing the mapping, you are using :imap <C-c>a, where the second c is lowercase, but in the unmap <C-C>a commands, your second C is uppercase.
Since these commands are generally case-sensitive, I suspect that might be part of your issue.

vim key mapping to existing key

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.

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.

Combine two vim commands into one

I'm having trouble combining two vim commands, specifically <C-w>s and <leader>x into <leader>r (i.e. split window and open spec counterpart of current file). Any help?
Thanks!
It would help if you'd post what exactly you've tried that didn't work. Generally, doing what you describe should be simple. It should be enough to put this in your .vimrc file:
nmap <leader>r <c-w>s<leader>x
This maps <leader>r to expand to the key sequence <c-w>s<leader>x. Note that these are not "commands", as you call them in your question, they're "mappings". A "command" is something completely different in vim, you can read up on that with :help user-commands.
One thing to be careful of is using nmap instead of nnoremap. The command nmap maps the sequence on the left to the sequence on the right while re-using mappings that have already been defined. On the other hand, nnoremap creates a mapping with the original meanings of the keys, so in your case won't work (since <leader>x is defined by some plugin). This is one possible reason you may have failed while trying to do it, but I can't tell from your question.

Resources