如何为vim安装插件?

Eth*_*han 146 vim

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

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

我这样做了......

$ cd ~/.vim
$ git clone git://github.com/tpope/vim-haml.git
Run Code Online (Sandbox Code Playgroud)

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

小智 131

确保实际.vim文件在~/.vim/plugin/

  • 谢谢你的简单回答! (17认同)

Kar*_*tin 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
Run Code Online (Sandbox Code Playgroud)


jam*_*san 45

为了扩展Karl的回复,Vim在一组特定的目录中查找其运行时文件.你可以看到那组目录:set runtimepath?.为了告诉Vim也要向内看~/.vim/vim-haml你想要添加

set runtimepath+=$HOME/.vim/vim-haml
Run Code Online (Sandbox Code Playgroud)

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

filetype plugin indent on
syntax on
Run Code Online (Sandbox Code Playgroud)

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

  • 当您以交互方式键入它们时,需要使用":"进入cmdline模式.在脚本中,不需要它们,因为脚本处于cmdline模式,可以这么说.因此,在脚本中省略':'是标准做法,因为它只会增加不必要的混乱. (4认同)

yng*_*gve 19

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

或者,或许,您可能更喜欢Vundle,它提供类似的功能(还有来自github中插件的自动更新的额外好处).