如何为vim安装插件?

我想尝试下面链接的Vim的插件。 它为.haml和(可能) .sass文件添加语法高亮。

http://github.com/tpope/vim-haml

我做了这个…

 $ cd ~/.vim $ git clone git://github.com/tpope/vim-haml.git 

我在Vim中打开了一个.haml文件,但没有突出显示。 必须有另一个步骤,我需要执行。

这两个命令将创build一个带有ftplugin,syntax等目录的~/.vim/vim-haml/目录。 这些目录需要立即在~/.vim目录中,或者需要将~/.vim/vim-haml添加到vimsearch插件的path列表中。

编辑:

我最近决定调整我的vimconfiguration,并在写入以下rakefile的过程中。 它只适用于Mac / Linux,但与cp版本相比,它的优势在于它完全安全(符号链接不会覆盖现有文件,卸载只会删除符号链接),并且易于更新。

 # Easily install vim plugins from a source control checkout (eg Github) # # alias vim-install=rake -f ~/.vim/rakefile-vim-install # vim-install # vim-install uninstall require 'ftools' require 'fileutils' task :default => :install desc "Install a vim plugin the lazy way" task :install do vim_dir = File.expand_path("~/.vim") plugin_dir = Dir.pwd if not (FileTest.exists? File.join(plugin_dir,".git") or FileTest.exists? File.join(plugin_dir,".svn") or FileTest.exists? File.join(plugin_dir,".hg")) puts "#{plugin_dir} isn't a source controlled directory. Aborting." exit 1 end Dir['**/'].each do |d| FileUtils.mkdir_p File.join(vim_dir, d) end Dir["**/*.{txt,snippet,snippets,vim,js,wsf}"].each do |f| ln File.join(plugin_dir, f), File.join(vim_dir,f) end boldred = "\033[1;31m" clear = "\033[0m" puts "\nDone. Remember to #{boldred}:helptags ~/.vim/doc#{clear}" end task :uninstall do vim_dir = File.expand_path("~/.vim") plugin_dir = Dir.pwd Dir["**/*.{txt,snippet,snippets,vim}"].each do |f| safe_rm File.join(vim_dir, f) end end def nicename(path) boldgreen = "\033[1;32m" clear = "\033[0m" return "#{boldgreen}#{File.join(path.split('/')[-2..-1])}#{clear}\t" end def ln(src, dst) begin FileUtils.ln_s src, dst puts " Symlink #{nicename src}\t => #{nicename dst}" rescue Errno::EEXIST puts " #{nicename dst} exists! Skipping." end end def cp(src, dst) puts " Copying #{nicename src}\t=> #{nicename dst}" FileUtils.cp src, dst end def safe_rm(target) if FileTest.exists? target and FileTest.symlink? target puts " #{nicename target} removed." File.delete target else puts " #{nicename target} is not a symlink. Skipping" end end 

确保实际的.vim文件在〜/ .vim / plugin /

为了扩展Karl的回复,Vim为其运行时文件寻找一组特定的目录。 你可以通过:set runtimepath?方式看到这组目录:set runtimepath? 。 为了让Vim也看看~/.vim/vim-haml里面~/.vim/vim-haml你需要添加

 set runtimepath+=$HOME/.vim/vim-haml 

到你的~/.vimrc 。 您可能还需要在~/.vimrc中启用以下function来启用vim-haml提供的所有function。

 filetype plugin indent on syntax on 

有关更多信息,可以参考Vim中的'runtimepath':filetype帮助主题。

我想你应该看看病原体插件 。 安装完成后,您可以将所有插件保存在〜/ .vim / bundle /中的不同文件夹中,Pathogen会负责加载它们。

或者,也许你更喜欢Vundle ,它提供了类似的function(带有github插件自动更新的额外好处)。