Linux下 Vundle安装和使用 Vim实现代码跳转

Linux下 Vundle安装和使用 Vim实现代码跳转

安装依赖

Vundle是vim的一个插件管理器, 同时它本身也是vim的一个插件,可以搜索、安装、更新、清理插件。Vundle的安装需要git和curl的支持。如果没有上述两个套件可以先下载。
yum install crul
yum install git

安装Vundle

首先下载所需文件

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

修改~/.vimrc文件,如果你不是root用户,那么请修改对应用户目录下的.vimrc文件,比如用户名是bar,请修改/home/bar/.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/'}
" 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然后输入

​ :PluginInstall

Vundle会自动安装配置文件里 call vundle#begin()call vundle#end()之间记录的插件,安装完成后会显示done。过程可能有点费时间。

2.从命令行安装

在命令行中输入:vim +PluginInstall +qall,等待一段时间直到显示done

使用代码跳转功能

用vim打开源码文件,将光标放在要查看的函数上,Ctrl+]可以跳转,Ctrl+t可以返回,如果有多个跳转选项,按数字键选择跳转到哪一个。

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配置文件,可以通过设置别名解决

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