I'm new to Vim, and for the paste couple of weeks, I've been using NERDTree with no problems. However, I recently added a few key mappings and am now unable to open NERDTree with the <C-n> command. Nothing happens when I run the command.

Here's the part of my .vimrc that I found to be causing the problem.

" Map semicolon to colon and vice versa
nnoremap ; :
nnoremap : ;

" Map shortcuts to align = for Tabularize
vmap <Leader>a= :Tabularize /=<CR>
" The following line doesn't work as well.
nmap <Leader>a= :Tabularize /=<CR>

Once I remove the nnoremap : ; command, NERDTree begins working again. Why is this happening, and how can I fix it?

Additionally, the shortcut to call Tabularize works in the visual mode but not in insert mode. I don't know if this and the NERDTree problems are related.

Background information: I'm running Vim 7.4.52 on bash on Windows (Windows Subsystem for Linux).

  • Welcome to our site. This question How do I debug my vimrc should allow you to isolate the issue. Once you find what code causes your issue, you can edit your question to be more precise about your problem and we can reopen the question. – statox Apr 23 '18 at 9:03
  • 1
    @statox, I've isolated the issue and updated my question. – Mohideen Imran Khan Apr 23 '18 at 9:16

The problem is that when you invoke your Tabularize mapping, the : in the right-hand-side of the mapping is remapped to a ; by your colon map, and the keystrokes that are then invoked are:

;Tabularize /=<CR>

In order to fix this, you need to tell your Tabularize mapping to ignore existing mappings, and instead use the default functionality. You do this by using the non-recursive form of the map command:

nnoremap <Leader>a= :Tabularize /=<CR>

This tells Vim to use an actual colon, and to ignore anything that colon (and everything else in the rhs) may be mapped to.

Note that your vmap command is subject to similar issues: it's just that you don't currently have colon mapped to anything in visual mode, so it works by happenstance. To make your mapping robust, you should use vnoremap here, similarly.

I imagine this is also causing your NERDTree issue: I don't believe Ctrl-N is a standard keystroke for opening NERDTree, so you've probably got that set up as a mapping in your .vimrc somewhere, and it's probably not using the non-recursive form of the map command.

As a general rule of thumb, you should always use the nore forms of the various map commands, only using the bare forms if you have a specific reason to do so, which will happen infrequently (or never!)

  • Yup, once I replaced nmap with nnoremap for NERDTree, the problem was solved. Thanks for the help! – Mohideen Imran Khan Apr 30 '18 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.