Tuesday, March 11, 2014

Re: How should I modify a normal mode map set by a plugin?

Hello Ethan,

Ethan Hereth <advocateddrummer@gmail.com> a écrit:
> I have a question that I think should have a better answer.
>
> I used to have a couple normal mode maps in my .vimrc that went like this:
>
> nnoremap n nzz
> nnoremap N Nzz
>
> which, as I'm sure I don't need to tell most of you, causes the next search result to be centered (usually) when the user presses n/N. These maps worked great for a long time... Until I installed the IndexedSearch plugin, which I do really like by the way. This broke my maps which annoyed me for quite some time until today when I decided to track down the cause.
>
> Typing 'verbose map n' gave me the following:
>
> n n * :let v:errmsg=''<CR>:silent! norm! n<CR>:call <SNR>34_ShowCurrentSearchIndex(0,'!')<CR>
> Last set from ~/.vim/bundle/IndexedSearch/plugin/IndexedSearch.vim
>
> So now I see that the IndexedSearch plugin has stolen my maps. So, for now I have changed the appropriate lines in the IndexedSearch.vim plugin as follows to get back the previous behavior without losing IndexedSearch's addition. So, I'm happy now.
>
> nnoremap <silent>n :let v:errmsg=''<cr>:silent! norm! nzz<cr>:call <SID>ShowCurrentSearchIndex(0,'!')<cr>
> nnoremap <silent>N :let v:errmsg=''<cr>:silent! norm! Nzz<cr>:call <SID>ShowCurrentSearchIndex(0,'!')<cr>
>
> My question is: Is there a better way to do this? Instead of actually modifying the plugin code I'd like to simply modify the map after IndexedSearch has set it. I did skim both Google and ':help map' but nothing popped out at me as answering my question.

Add a plugin in your "after" directory, e.g.:

" Beware, no 'noremap' this time!
nmap n nzz
nmap N Nzz

in "$HOME/.vim/after/plugin/IndexedSearch.vim" (replace ".vim" with
"vimfiles" if you're on Windows). Files in "after" are loaded, well,
after anything else.

Best,
Paul

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: