2015年4月19日 星期日

mac 安裝 vim 的插件管理 Vundle

webber0928

簡介

Vim作為史上最強大的編輯器之一,擁有數以萬計的插件。Vim的生態系統一如Apple Store,完美的插件機制,鑄造了Vim的經典傳奇,但遺憾的是一直沒有好的插件管理工具,讓很多優秀的插件相忘於江湖。Vundle也許不是最完美的解決方案,卻是現存最好的Vim插件管理方案,用Vundle管理插件的好處:

  • 自動下載安裝
  • 自動更新
  • 重裝或換機器,只需保存一份配置文件
  • 自動清理沒用的插件

安裝

Mac和Linux安裝比較簡單,按照官方教程指導即可。Windows下稍微有點麻煩。

下載地址

Mac和Linux安裝

1.安裝git客戶端
Mac和Linux一般默認已經安裝了git(沒有安裝的自行查找方法)
2.創建插件存儲文件夾mkdir ~/.vim/bundle/
3.下載並安裝Vundle git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/
注:也可直接下載zip包,解壓到vim目錄(但還是建議裝git,因為Vundle主要通過git下載插件包)
4.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 'gmarik/Vundle.vim'

" -----------------自定義插件官方示例start-----------------------
" 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 (ie 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/'}
" Avoid a name conflict with L9
Plugin 'user/L9', {'name': 'newL9'}
" ------------------自定義插件官方示例end------------------------- -

" 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

Windows

Windows的配置方法類似,只是有幾個地方要注意。
參考教程:https://github.com/gmarik/Vundle.vim/wiki/Vundle-for-Windows 
注:這個教程有點問題,完全按照所寫的步驟,並不能成功配置。
1.git windows客戶端
按照教程中所示下載msysgit
2.vim安裝文件夾
windows下的安裝目錄結構跟Unix-like操作系統不一樣,分為兩部分:
vim74 #主程序目錄對應變量$VIMRUNTIME
vimfiles #配置文件目錄對應變量$VIM
3.配置文件
" 配置同Mac,只需要按照下面修改rtp的路徑即可
set rtp+=$VIM/vimfiles/bundle/Vundle.vim/
let path='$VIM/vimfiles/bundle'
call vundle#rc(path)

" call vundle#end() # **這一句需要註釋或刪掉**
4.關於vimrc的一個小建議
vimrc與vundle_vimrc分開管理,如下:
4.1創建vundle_vimrc(不是固定名稱,可自定義)
專門用來配置vundle插件以及插件的自定義選項,示例:
set nocompatible " be iMproved
filetype off " required!

set rtp+=$VIM/vimfiles/bundle/Vundle.vim/
let path='$VIM/vimfiles/bundle'
call vundle#rc(path)

" Vundle *必須
Plugin 'gmarik/Vundle.vim'

" original repos on github (Github倉庫)

" 前端開發神器,自動生成html/css代碼
Plugin 'mattn/emmet-vim'
"===emmet只在html和css文件中起作用===
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
"Plugin 'drmingdrmer/xptemplate'

" vim-scripts repos (vim-scripts倉庫)
Bundle 'L9'
Bundle 'FuzzyFinder'

" non github repos (非以上兩種)
Bundle 'git://git.wincent.com/command-t.git'

filetype plugin indent on " required!
4.2 vimrc中加入:
" 引用自定義的vundle配置文件
source $VIM/vundle_vimrc #存放vimrc的地方(不是固定寫法,可自定義)

使用

使用方法很簡單,只需3步使新插件生效即可
1.將目標插件配置進vimrc或vundle_vimrc
2.執行:PluginInstall
3.重啟

常用命令

:PluginList - 枚舉已安裝的插件列表
:PluginInstall - 安裝插件或者後面加上'!'更新
:PluginUpdate - 更新插件同:PluginInstall!
:PluginSearch foo - 查找插件。例如查找名稱為foo的插件。或者後面加'!'更新本地緩存
:PluginClean - 清理無用插件或者後面加'!'自動清理

更多使用方法

:h vundle

文章出處

By webber0928

一個小菜鳥工程師,對籃球還有夢想的男孩。

0 意見:

張貼留言

Coprights @ 2016, Blogger Templates Designed By Templateism | Distributed By Gooyaabi Templates