Mac系统vim使用Vundle管理插件

/ 0评 / 3

Vim,是从vi发展出来的一个文本编辑器,终端下文本编辑利器。vim缺乏默认插件管理,在使用插件时,插件文件散布在~/.vim目录下,插件管理非常麻烦,很容易出错。今天就来介绍一款vim插件管理器:Vundle。

GitHub开源库:https://github.com/VundleVim/Vundle.vim

安装

使用git方式安装:

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

clone 完成后,打开~/.vimrc配置,增加如下内容,启用Vundle插件管理:

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

参考:https://github.com/VundleVim/Vundle.vim#quick-start

运行vim,输入:PluginInstall 完成第一次初始化安装。

插件安装

插件安装有两种方式:

1.修改vimrc,编辑~/.vimrc,把要安装的插件以Plugin 'xxx/xxx' 的格式添加到" call vundle#begin('~/some/path/here')call vundle#end() " required 之间,保存关闭。打开vim,执行:PluginInstall即可。

2.使用命令行vim +PluginInstall +qall

其他常用命令

更新插件 :BundleUpdate
列出所有插件 :BundleList
查找插件 :BundleSearch

我的vimrc文件

" https://github.com/VundleVim/Vundle.vim#quick-start
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'

" https://github.com/vim-airline/vim-airline
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

" https://github.com/w0rp/ale
" 代码检测
Plugin 'w0rp/ale'

" https://github.com/airblade/vim-gitgutter
" Git插件
Plugin 'airblade/vim-gitgutter'

" https://github.com/mhinz/vim-signify
"
Plugin 'mhinz/vim-signify'

call vundle#end()            " required
filetype plugin indent on    " required


" Configuration file for vim
set modelines=0     " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible    " Use Vim defaults instead of 100% vi compatibility
set backspace=2     " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup
" 非兼容vi模式。去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
" 文件修改之后自动载入
set autoread
" 显示高亮
syntax on
" 显示行号
set number
" 取消换行
set nowrap
" 为方便复制,用<F2>开启/关闭行号显示:
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
" 粘贴时保持格式
set paste

" 检测文件类型
filetype on
" 针对不同的文件类型采用不同的缩进格式
filetype indent on
" 允许插件
filetype plugin on
" 启动自动补全
filetype plugin indent on

" set background=dark
set ruler
" 设置Tab键的宽度,等同的空格个数
set tabstop=4
set smartindent
set shiftwidth=4
set expandtab
" 历史记录数
set history=1000
"搜索忽略大小写
set ignorecase
" 去掉输入错误的提示声音
"set noerrorbells
"set novisualbell
"set t_vb=
"set tm=500
" 开启鼠标模式
" set mouse=a
" 开启搜索高亮 == hlsearch
set hls

colorscheme  molokai
let g:rehash256 = 1
" https://stackoverflow.com/a/24570615/5784369
let g:airline#extensions#hunks#enabled=0

" 再次打开文件,光标自动跳转到上一次光标停留位置
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

一些问题

1.vim开启行数显示和语法高亮,在iTerm2下显示诡异:

修改iTerm2 的 Report terminal typexterm-256color 可以解决。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注