How to debug vim mapping overlaps? - vim

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.

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.

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 do I prevent snipmate from remapping <S-Tab>?

In my after.vim config I have line:
inoremap <S-Tab> <C-d>
I would like this binding to work. However, after starting VIM I type the first line and get the following output:
:verbose map <S-Tab>
s <S-Tab> * <Esc>i<Right><C-R>=BackwardsSnippet()<CR>
Last set from ~/dotvim/bundle/snipmate.vim/after/plugin/snipMate.vim
So snipmate is overwriting the mapping. I understand I could change it within the /bundle/snipmate.vim/after/plugin/snipMate.vim file, but that seems really ugly because I've got /bundle in my .gitignore, which seems to be standard practice.
Any ideas on how to override this, or prevent snipmate from binding to <S-Tab> ?
To remap the command executed by <S-Tab> to <C-d> add the following line to your .vimrc
imap <C-d> <Plug>snipMateBack
The snipmate documentation states you should remap <Plug>snipMateBack in your ~/.vimrc. See :h SnipMate-mappings.
Generally using a vim distribution (which you are) is considered bad for new vimmers because it disrupts learning Vim and puts up barriers when a user decides to customize (as you see here). Personally I would suggest you lose the distribution. Go find a nice plugin manager like pathogen and install plugins when you need them. Doing this means you grow your understanding of Vim as you customize it.
If really do want to use a distribution then you should first try submitting an issue to your distributions issue tracker.

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.

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