Thursday, March 5, 2015

Re: Like vimrc, but executed last

2015-03-05 21:10 GMT+03:00 Paolo Bolzoni <paolo.bolzoni.brown@gmail.com>:
> Dear list,
>
> I have this line in my .vimrc
>
> inoremap <nl> <esc>
>
> And normally it works fine, I can leave insert mode pressing
> ctrl-enter.
>
> However, I am using quite a bit of plugins when using vim for C++
> editing and somewhere <nl> in normal mode get remapped in
> apparently nothing.

`inoremap` is a insert-mode mapping. I do not understand how normal
mode is related. Assuming you meant insert mode.

>
> So I was wondering, is there any file like .vimrc that actually
> is executed last?

I guess you should put

iunmap <buffer> <NL>

into ~/.vim/after/ftplugin/cpp.vim. If the offending plugin was
written by some badass then you should also repeat

inoremap <NL> <Esc>

there

Notes:

1. If this happens in a C++ plugin then 90% this means it is
buffer-local mapping. You will achieve nothing by repeating this
`inoremap` then because buffer-local mappings do not remove global
mappings, yet they have priority over them: your mapping is
overridden, not replaced in this case.
2. If this happens in a C++ plugin then 95% this means that it happens
in a ftplugin. VimEnter runs too early if you happen to open new file,
you need sometimes running on FileType event.
3. If you meant that when editing C++ files you enable additional
non-filetype plugins you should move your mapping (not `iunmap`) to
~/.vim/after/plugin/….vim or use VimEnter.

4. ~/.vim/after directory is nothing special. By default it is the
last directory in &runtimepath and this is why this solution is
launched last. If you e.g. have a plugin manager that puts directories
after ~/.vim/after or you put C++ ftplugin the last by hand then don't
be surprised that the solution is not going to work.
I repeat, Vim has nothing that guarantees contents of ~/.vim/after
well be executed the last. It is just the consequence of the default
value of &runtimepath option.

5. To check who defined your mapping use `verbose imap <NL>`.



>
>
> Yours faithfully,
> Paolo
>
> --
> --
> 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.

--
--
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:

Post a Comment