###

alias hbin me

Resolving Vim Key Mapping Conflict

Ack.vim is a plugin for the Perl CLI script ack which is a replacement of grep. It provides a front for running ack from vim.

By default, It will search recursively under the current directory. It’s not convenient to search of a project.

Fortunately, there is a plugin vim-rooter which will changes the working directory to the project root automatically.

I use Janus for my Vim. So I git clone it to ~/.janus directory. It works great, but if I open Vim from the terminal, I got a key mapping conflict error message:

1
2
3
Error detected while processing /Users/hbin/.janus/vim-rooter/plugin/rooter.vim:
line  159:
E227: mapping already exists for ,cd

That’s because Janus mapped <leader>cd to changes the path to the active buffer’s file, and the vim-rooter also try to map <leader>cd to <Plug>RooterChangeToRootDirectory.

Here is the source

1
2
3
if !hasmapto("<Plug>RooterChangeToRootDirectory")
  map <silent> <unique> <Leader>cd <Plug>RooterChangeToRootDirectory
endif

The Solution is simple, just create a mapping to <Plug>RooterChangeToRootDirectory:

1
nnoremap <leader>cr <Plug>RooterChangeToRootDirectory

References:

  1. http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_1)
  2. http://stackoverflow.com/questions/3776117/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping

Enjoy!

Comments