开发者

How do I get Vim's project plugin to load the in.vim on external buffer change?

开发者 https://www.devze.com 2023-01-29 12:43 出处:网络
I\'m using the project plugin in Vim. For each project I\'m working on, I have set up an own in.vim/out.vim where the project-specific stuff gets set.

I'm using the project plugin in Vim. For each project I'm working on, I have set up an own in.vim/out.vim where the project-specific stuff gets set.

For example, I set a shiftwidth of 2 in the in.vim, 开发者_运维问答whereas in my .vimrc, I set it to 4. When I'm opening a file from the project tree, everything is fine: the sw is 2. Now, I compile the sources (Visual Studio) and get some compiler errors/warnings. Switch to Visual Studio, fix the errors, back to Vim then.

My editor did realize that I changed the file outside the editor and asks me to reload the file. After confirming the reload, the sw is set to 4.

Obviously, this is because the .vimrc is getting read on buffer reload and overwrites my setting of the shiftwidth stored in the in.vim configuration file.

My question is: is there any way to bring the project plugin (or vim itself) to load the in.vim upon buffer refresh?

Solution

The answer of ZyX pointed me to a handling that works for me:

  1. In the in.vim, set a global variable to the path of in.vim:

    let g:invimpath = "D:/project/vimstuff/in.vim"

  2. In the .vimrc, try to load this specified file when FileChangedShellPost occurs:

    autocmd FileChangedShellPost * if exists("g:invimpath") | exe 'source ' . g:invimpath | endif

Credits go to ZyX to point me to this path.


Yes, it is, with FileChangedShellPost autocommand, but I suggest you first add the following just before the beginning of your vimrc (but after scriptencoding statement, if it is present):

if exists("s:vimrc_loaded")
    finish
endif
let s:vimrc_loaded=1
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号