简体   繁体   中英

How can i prevent my vim plugins being overridden by older ones?

I have installed MacVim via homebrew, and pathogen via downloading the pathogen.vim file to my ~/.vim/autoload directory. I have got cloned the vim-perl plugin into ~/.vim/bundle directory.

However, when i open a perl file, it uses the syntax highlighting from the perl.vim file included with MacVimand not my downloaded plugin. This is the output of :scriptnames . Note all the MacVim supplied plugins are there and I think the perl ones listed last overwrite my downloaded plugin:

1: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/vimrc
2: ~/.vimrc
3: ~/.vim/autoload/pathogen.vim
4: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/ftoff.vim
5: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
6: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
7: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
8: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/filetype.vim
9: ~/.vim/bundle/vim-javascript/ftdetect/javascript.vim
10: ~/.vim/bundle/vim-perl/ftdetect/mason-in-html.vim
11: ~/.vim/bundle/vim-perl/ftdetect/perl11.vim
12: ~/.vim/bundle/vim-ruby/ftdetect/ruby.vim
13: ~/.vim/bundle/vim-scala/ftdetect/scala.vim
14: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/menu.vim
15: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/autoload/paste.vim
16: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
17: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/indent.vim
18: ~/.vim/colors/default.vim
19: ~/.vim/bundle/vim-scala/plugin/scala.vim
20: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/getscriptPlugin.vim
21: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/gzip.vim
22: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/matchparen.vim
23: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
24: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/rrhelper.vim
25: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/spellfile.vim
26: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/tarPlugin.vim
27: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/tohtml.vim
28: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/vimballPlugin.vim
29: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/plugin/zipPlugin.vim
30: ~/.vim/bundle/vim-scala/after/plugin/help.vim
31: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/gvimrc
32: ~/.vim/bundle/vim-perl/syntax/perl.vim
33: ~/.vim/bundle/vim-perl/syntax/pod.vim
34: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/syntax/pod.vim
35: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/syntax/perl.vim
36: ~/.vim/bundle/vim-perl/ftplugin/perl.vim
37: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/ftplugin/perl.vim
38: ~/.vim/bundle/vim-perl/indent/perl.vim
39: /usr/local/Cellar/macvim/7.4-73/MacVim.app/Contents/Resources/vim/runtime/indent/perl.vim

Here is my ~/.vimrc file

set shell=/bin/sh

call pathogen#infect()

filetype off
syntax on
filetype plugin indent on

If I :so ~/.vim/bundle/vim-perl/syntax/perl.vim then the file syntax highlights correctly.

How can I prevent the MacVim bundled ones overriding?

The inclusion guard ( if exists("b:current_syntax") ) should prevent the default Perl syntax script from having any effect (after your custom one has been sourced).

As a workaround, you could move your own script from ~/.vim/bundle/vim-perl/syntax/perl.vim to ~/.vim/bundle/vim-perl/after/syntax/perl.vim , or alternatively create a ~/.vim/after/syntax/perl.vim script with

so ~/.vim/bundle/vim-perl/syntax/perl.vim

in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM