前言:
- 在代碼編輯的過程中, 我們常常要使用 "", (), [], {} 等符號來包圍一個變量或表達(dá)式, 或者是刪除文本周圍的包圍符號.
- 這樣的操作即使是使用 vim 提供的 { command + text objext/motions } 操作來實現(xiàn), 仍然會十分繁瑣. 于是我們會需要借助 vim-surround 這樣的插件, 來簡化操作以提高效率, 做一個lazy coder. 在這個需求下, 使用vim插件管理器來快捷地管理對應(yīng)插件就變得十分有必要.
- 本文將會討論vim插件管理器 vundle 的安裝和使用.
vundle
- vundle 是一個 vim 的插件管理工具. 可以用于從本地和遠(yuǎn)程的git倉庫 安裝/更新vim的插件.
- 參考: VundleVim/Vundle.vim?github.com
安裝 vundle
- 使用 git 克隆到本地
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
使用 vundle 安裝vim插件
流程簡述
要使用 vundle 安裝vim插件, 首先需要在 vundle 的配置文件中定義/輸入所需的插件, 然后使用 vim 命令來完成安裝.配置vundle插件
將以下內(nèi)容復(fù)制為 ~/.vimrc 文件, 然后根據(jù)自己的需求來替換定義插件的示范文本.
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vimcall
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
"--------------------------------------- 定義插件結(jié)束 ---------------------------------------
call vundle#end() " required
filetype plugin indent on " required
- 添加 vim 插件到配置中 ( 以 vim-surround 為例) :
將這一行復(fù)制到 .vimrc 的插件定義部分
Plugin 'tpope/vim-surround'
- 執(zhí)行安裝:
進(jìn)入 vim
鍵入以下命令
:PluginInstall
// 或
:PluginUpdate
結(jié)語??
至此, 我們就成功地通過 Vundle 添加了一個 vim 插件, 如果要使用其他的 vim 插件管理器 (例如 vim-plug) 來管理 vim 創(chuàng)建, 同樣需要進(jìn)行上文中的類型配置, 具體的操作請參考相應(yīng)的 github repo.