用Vundle管理Vim插件

时间:2022-06-09 17:20:42

作为程序员,一个好用的Vim,是极其重要的,而插件能够使原本功能羸弱的Vim变得像其他功能强大的IDE一样好用。然而下载、配置插件的过程比较繁琐,大家往往需要自己进行下载/配置等操作,如果还涉及到更新/删除插件,那就更麻烦了。

幸运的是我们有Vundle来管理Vim插件。Vundle本身就是个Vim插件,有了这个插件,我们只需要配置好~/.vimrc这个文件,就可以通过命令管理其他Vim插件了,非常好用。下面我们就介绍如何使用它吧!(以下都是在Linux系统内操作)

如何安装:

Step1: 直接用git,将Vundle下载下来。

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Step2: 配置插件(Plugins)。 将下面的配置信息写到你的.vimrc文件中(一般情况下,我们vimrc的路径为"~/.vimrc",如果没有,就创建),然后保存。

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

Step3: 安装插件,打开vim,运行如下命令即可安装。

:PluginInstall

Step4: 查看安装状态

. Plugin 'VundleVim/Vundle.vim'                           
. Plugin 'tpope/vim-fugitive'                             
. Plugin 'rstacruz/sparkup'                             
+ Plugin 'tomasr/molokai'                                     
+ Plugin 'scrooloose/nerdtree'                                 
+ Plugin 'Lokaltog/vim-powerline'                        
+ Plugin 'bling/vim-airline'                                   
+ Plugin 'SublimeText/CTags'                                     
+ Plugin 'Valloric/YouCompleteMe'                                
+ Plugin 'majutsushi/tagbar'

执行完Step3的命令后,会显示上面的安装进度,下面是如何读懂安装进度的说明。

'.'代表已经此前安装过的插件。

'+'代表本次安装的插件。

确认安装完成后,用命令":q"退出即可。

Step5: 添加/删除插件。

下面介绍几个好用的插件:

Plugin 'tomasr/molokai' 好用的配色
Plugin 'scrooloose/nerdtree' 方便文件管理
Plugin 'Lokaltog/vim-powerline' 下方的状态
Plugin 'bling/vim-airline' 好看的配色
Plugin 'SublimeText/CTags' 有tags方便补全
Plugin 'Valloric/YouCompleteMe' 功能强大的补全
Plugin 'majutsushi/tagbar' 显示变量和函数名

比如我们想添加 'tomasr/molokai'这个插件,只需要把 Plugin 'tomasr/molokai'添加到.vimrc中有关Plugin插件的那一段中,然后执行:PluginInstall命令安装就好。

如果想删除插件,同理。

 

参考链接:

如何在Linux上使用vundle管理vim插件 https://linux.cn/article-9416-1.html