如何为vim安装插件?

时间:2009-10-28 19:42:31

标签: vim

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

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

我这样做了......

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

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

5 个答案:

答案 0 :(得分:130)

确保实际的.vim文件位于~/.vim/plugin/

答案 1 :(得分:52)

这两个命令将创建一个~/.vim/vim-haml/目录,其中包含ftplugin,syntax等目录。这些目录需要立即在~/.vim目录中,或者~/.vim/vim-haml需要添加到vim搜索插件的路径列表中。

修改

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

# Easily install vim plugins from a source control checkout (e.g. 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

答案 2 :(得分:45)

为了扩展Karl的回复,Vim在一组特定的目录中查找其运行时文件。您可以通过:set runtimepath?查看该组目录。为了告诉Vim还要查看~/.vim/vim-haml,你需要添加

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

~/.vimrc。您可能还需要~/.vimrc中的以下内容来启用vim-haml提供的所有功能。

filetype plugin indent on
syntax on

您可以参考Vim中的'runtimepath':filetype帮助主题获取更多信息。

答案 3 :(得分:19)

我想你应该看一下Pathogen plugin。安装完成后,可以将所有插件保存在〜/ .vim / bundle /中的单独文件夹中,Pathogen将负责加载它们。

或者,或许你可能更喜欢Vundle,它提供了类似的功能(github中插件自动更新的额外好处)。

答案 4 :(得分:1)

更新(截至2019年):

cd ~/.vim
git clone git://github.com/tpope/vim-haml.git pack/bundle/start/haml

说明(来自:h pack广告:h packages):

  1. 找到的所有目录都添加到runtimepath中。它们必须放在〜/ .vim / pack / whatever / start 中[您只能更改任何内容]。
  2. plugins的{​​{1}}目录中找到的插件都是

因此这会在启动时加载插件(因此名称为start)。

如果将它们放在〜/ .vim / pack / bundle / opt runtimepath加载)。 >