作为编辑器之神的vim,初安装时,就像十几岁的孩子,潜力无限但能力有限。所以当我们要充分开发它的潜能时,那么就不得不对vim进行扩展,也就是安装插件。(当然了,如果你不想定制自己所需要的插件,只是想一键安装,然后满足你几乎所有对vim的需求,那么你可以尝试spf13-vim github地址:https://github.com/spf13/spf13-vim) 下面介绍部分插件的安装,以满足基本的代码阅读或者项目开发的需求。
本文介绍的vim配置的核心思路是以Vundle为管理器,在此基础上,进行其他插件的安装和管理。
由于后续可能安装的插件越来越多,因此在安装其他插件之前先安装一个插件管理器Vundle,它可以更新,安装或者卸载我们的插件,十分方便。 1.git clone
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
2.修改vim配置文件 /home/username/.vimrc(注:username指你的用户名) tips:如果你要修改全局的配置,对所有用户生效,可以修改系统配置,打开vim,
:version
可以看到不同位置的vimrc
系统 vimrc 文件: "$VIM/vimrc"
用户 vimrc 文件: "$HOME/.vimrc"
第二用户 vimrc 文件: "~/.vim/vimrc"
用户 exrc 文件: "$HOME/.exrc"
系统 gvimrc 文件: "$VIM/gvimrc"
用户 gvimrc 文件: "$HOME/.gvimrc"
第二用户 gvimrc 文件: "~/.vim/gvimrc"
系统菜单文件: "$VIMRUNTIME/menu.vim"
$VIM 预设值: "/usr/share/vim"
修改不同位置的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'
"下面是三种实例方式安装插件
"从github安装,作者名/插件名称
"Plugin 'tpope/vim-fugitive'
"从vim-scripts安装的,直接使用插件名
" Plugin 'L9'
"没有托管在github的插件,使用git全地址
"Plugin 'git://git.wincent.com/command-t.git'
"本地插件,比如自己编写的插件
"Plugin 'file:///home/gmarik/path/to/plugin'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
添加完成后,打开vim,输入
:PluginInstall
安装Vundle,等待安装完成 Vundle基本命令
:BundleUpdate "更新插件
:BundleList "列出所有插件
:BundleSearch "查找插件
:BundleInstall "安装插件
:BundleClean "清除插件
接下来就是安装我们需要的插件了。
接下来,我们将安装以下插件
有了以上这些插件,vim就如虎添翼了。
在前面的vimrc文件中,添加下面内容
" All of your Plugins must be added before the following line
之前,添加要安装的插件(未一一列举,可根据自己的需要添加或减少)
"taglist start
Plugin 'taglist.vim'
"taglist end
"ctags start
Plugin 'https://github.com/universal-ctags/ctags.git'
"ctags end
"nerdtree start,file tree
Plugin 'https://github.com/scrooloose/nerdtree.git'
"nerdtree end
"youcompleteme start
"Plugin 'https://github.com/Valloric/YouCompleteMe.git'
"youcompleteme end
"ctrlp start,find file
Plugin 'https://github.com/kien/ctrlp.vim'
"ctrlp end
"NerdCommenter start
Plugin 'https://github.com/scrooloose/nerdcommenter.git'
"NerdCommenter end
添加完成后保存。
打开vim,执行命令
:BundleInstall
等待自动安装完成。 当然你也可以通过apt-get的方式安装插件,例如
sudo apt-get install cscope
sudo apt-get install ctags
但是这样的安装方式是不在vundle的管理范围的。
经过以上步骤,我们需要的插件就已经安装上了。
set nu "显示行号
set showcmd "显示输入命令
set tabstop=4 "设置tab键缩进
"set autoindent "设置自动缩进
set cindent "c/c++缩进
set clipboard+=unnamed "共享剪切板
set mouse=a "设置鼠标可用
另外:如果vim无法复制粘贴剪切板内容,使用命令查看
vim --version | grep "clipboard"
出现 -clipboard表明不支持剪切板复制,需要安装图形化vim,并且修改vim配置,使得set mouse=v
sudo apt-get install vim-gnom #安装图形化vim
let Tlist_Ctags_Cmd='ctags'
let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_WinWidt =28 "设置taglist的宽度
let Tlist_Exit_OnlyWindow=1 "如果taglist窗口是最后一个窗口,则退出vim
"let Tlist_Use_Right_Window=1 "在右侧窗口中显示taglist窗口
let Tlist_Use_Left_Windo =1 "在左侧窗口中显示taglist窗口
let Tlist_Auto_Open=1
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
“设置快捷键
nmap <C-/>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-/>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-/>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-/>d :cs find d <C-R>=expand("<cword>")<CR><CR>
let NERDTreeQuitOnOpen=1 "打开文件时,关闭树
nnoremap <silent> <F2> :NERDTree<CR> "配置快捷键
let NERDTreeShowBookmarks=1
安装完成后,效果图如下:
图的左上方是树形目录,中间是文件函数,宏等内容,右边是源文件,最下方则是通过cscope查找找的函数调用结果。
以上内容仅对vim的基本安装和配置做简单说明,对于新安装其他插件,可以参照前面所提到的方法和思路。以上配置对于基本的开发,阅读源码来说,已经足够了。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有