Vim 经典插件介绍

1. ctags

功能:对浏览代码非常的方便, 可以在函数, 变量之间跳来跳去等等

安装:

sudo apt-get install ctags

或者从http://ctags.sourceforge.net/下载源代码包后,解压缩生成源代码目录

$ tar -xzvf ctags-5.6.tar.gz
$ cd ctags-5.6
$ make
$ make install   // 需要root权限

设置:

然后去你的源码目录, 如果你的源码是多层的目录, 就去最上层的目录, 在该目录下运行命令:

$ ctags -R

此时在该目录下会生成一个 tags 文件, 现在用vim打开该目录下任意文件:

$ vim main.cpp

再在vim中运行命令,该命令将tags文件加入到vim中来

:set tags="刚才生成的那个tags的完整路径"

使用:

把光标定位到某一函数名上,按下 Ctar + ],vim就可以自动切换到函数定义处!要返回只需要按下Ctrl + t 。
更多用法, 在vim命令模式输入:

:help usr_29 

2. taglist

功能:高效地浏览源码, 其功能就像vc中的workpace,列出了当前文件中的所有宏,全局变量,函数名等。

安装:

1)可从 http://vim-taglist.sourceforge.net/download.html 选择从Sourceforge或Vim online中下载

2)进入~/.vim目录,将Taglist安装包解压,解压后会在~/.vim目录中生成几个新子目录,如plugin和doc(安装其它插件时,可能还会新建autoload等其它目录)。

3)进入~/.vim/doc目录,在Vim下运行"helptags ."命令。此步骤是将doc下的帮助文档加入到Vim的帮助主题中,这样我们就可以通过在Vim中运行“help taglist.txt”查看taglist帮助。

设置:

打开配置文件~/.vimrc,加入以下几行:

let Tlist_Show_One_File=1            #不同时显示多个文件的tag,只显示当前文件的    
let Tlist_Exit_OnlyWindow=1          #如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Ctags_Cmd="/usr/bin/ctags" #将taglist与ctags关联  

使用:

此时用vim打开一个源文件试试:

$ vim main.cpp

进入vim后用下面的命令打开taglist窗口:

:Tlist

按下ctrl+w切换源文件和Taglist窗口,如下按钮可以帮助操作

F1:打开帮助
回车键:跳到光标所在的标记的定义处(如将光标移到main函数,按回车键)
o:新建一个窗口,跳到标记定义处
p:预览标记定义(仍然在taglist窗口)
空格:显示标记的原型(如函数原型)
u:更新标记列表(比如源文件新增了一个函数,并在保存后,可在taglist窗口按u)
s:选择排序字段(暂时我也不知道什么意思)
d:删除光标所在的taglist文件(如用vi打开了两个文件f1.c,f2.c可以删除f1.c的标记)
x:放大/缩小taglist窗口
+:展开(指标记)
-:折叠
*:全部展开
=:全部折叠
[[:将光标移到前一个文件的起点
]]:将光标移到后一个文件的起点
q:退出taglist窗口
F1:关闭帮助

3. a.vim

功能:在 .h 和 .c/.cpp 文件中切换

安装:可从http://www.vim.org/scripts/script.php?script_id=31下载a.vim,把下载到的a.vim插件放到 $HOME/.vim/plugin 目录下即可

使用:

头/源文件切换命令
    :A 头文件/源文件切换
    :AS 分割窗后并切换头/源文件(切割为上下两个窗口)
    :AV 垂直切割窗口后切换头/源文件(切割为左右两个窗口)
    :AT 新建Vim标签式窗口后切换
    :AN 在多个匹配文件间循环切换
将光标所在处单词作为文件名打开
    :IH 切换至光标所在文件
    :IHS 分割窗口后切换至光标所在文件(指将光标所在处单词作为文件名打开)
    :IHV 垂直分割窗口后切换
    :IHT 新建标签式窗口后切换
    :IHN 在多个匹配文件间循环切换

4. vundle

功能:插件管理

安装:

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

设置:编辑如下内容到.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/'}
" 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
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

使用:

(1)安装插件:保存退出当前的vim,重新打开vim,在命令模式下输入命令PluginInstall

(2)移除插件:编辑.vimrc文件移除的你要移除的插件行,保存退出当前的vim,重新打开vim,在命令模式下输入命令PluginClean

5. YouCompleteMe

功能:代码自动补全

安装:

    1. 确保Vim版本至少是7.4,并且支持python2脚本,要在Vim中输入以下命令:

:version                #在Vim中输入可以查看Vim版本
:echo has(‘python’)     #查看是否支持python2,输出为1,则表示支持
                        #如果为0,则需要重新编译安装vim,在编译时添加python支持

    如果Vim版本过低,Ubuntu系统可以使用以下命令更新Vim版本,否则就要从源码编译安装了

$ sudo add-apt-repository ppa:fcwu-tw/ppa
$ sudo apt-get update
$ sudo apt-get install vim

    2. 通过Vundle安装YCM,在你的vimrc中添加

Plugin 'Valloric/YouCompleteMe'

    然后打开Vim,执行以下语句下载:

:PluginInstall

    也可以通过git命令直接远程拷贝所需文件:

git clone https://github.com/Valloric/YouCompleteMe.git /home/ubuntu/.vim/bundle/YouCompleteMe

    现在你需要等 Vundle 下载完 YCM,这可能会花比较久的时间,请耐心等待,接着在下载完了后开始编译:

cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
./install.py --clang-completer

    --clang-completer 是提供 C-family 语言支持的,不需要可以将其去掉,默认情况下它会去下载 clang,如果你已经有了 clang,则参数为 --system-libclang

使用:输入的时候自动提示

转载于:https://my.oschina.net/shou1156226/blog/791656

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值