Linux下 Vundle安裝和使用 Vim實現代碼跳轉

Linux下 Vundle安裝和使用 Vim實現代碼跳轉

安裝依賴

Vundle是vim的一個插件管理器, 同時它自己也是vim的一個插件,能夠搜索、安裝、更新、清理插件。Vundle的安裝須要git和curl的支持。若是沒有上述兩個套件能夠先下載。
yum install crul
yum install githtml

安裝Vundle

首先下載所需文件linux

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

修改~/.vimrc文件,若是你不是root用戶,那麼請修改對應用戶目錄下的.vimrc文件,好比用戶名是bar,請修改/home/bar/.vimrc文件,沒有.vimrc文件就建立一個。git

將如下文本追加到.vimrc文件中github

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/'}
" Avoid a name conflict with L9
Plugin 'user/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          - list configured plugins
" :PluginInstall(!)    - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!)      - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

用Vundle安裝插件,兩種方式

1.打開vim而後輸入

​ :PluginInstallvim

Vundle會自動安裝配置文件裏 call vundle#begin()call vundle#end()之間記錄的插件,安裝完成後會顯示done。過程可能有點費時間。segmentfault

2.從命令行安裝

在命令行中輸入:vim +PluginInstall +qall,等待一段時間直到顯示donewindows

使用代碼跳轉功能

用vim打開源碼文件,將光標放在要查看的函數上,Ctrl+]能夠跳轉,Ctrl+t能夠返回,若是有多個跳轉選項,按數字鍵選擇跳轉到哪個。app

vundle其餘命令,摘自Vundle官網

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

安裝後遇到的問題

  1. E492: Not an editor command:XXX。例以下面這樣
Error detected while processing /root/.vimrc:
line 14:
E492: Not an editor command: Plugin 'VundleVim/Vundle.vim'
line 19:
E492: Not an editor command: Plugin 'tpope/vim-fugitive'
line 23:
E492: Not an editor command: Plugin 'git://git.wincent.com/command-t.git'
line 28:
E492: Not an editor command: Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Press ENTER or type command to continue

這種狀況多是使用命令 vi 時纔出現而使用vim是不出現,這是因爲vi並非vim而使用vi時會讀取$HOME/.vimrc配置文件,能夠經過設置別名解決curl

alias vi=vim

也多是你直接複製了windows上的配置文件$HOME/.vimrc到linux,而windows中的換行符是/r/n,linux的換行符是/n。因此應該改配置文件$HOME/.vimrc
參考連接:
https://stackoverflow.com/questions/24185580/vundle-e492-not-an-editor-command-plugininstall
https://segmentfault.com/a/1190000003795535?utm_source=tag-newest函數

Vundle官網: https://github.com/VundleVim/Vundle.vim
引用: https://www.jianshu.com/p/1839f1fb3f08

相關文章
相關標籤/搜索