1、插件管理器
Vundle是一个流行的vim插件管理器,它的网址是https://github.com/VundleVim/Vundle.vim
以下是安装步骤:
- git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
如果目录.vim/bundle不存在请先创建 - 打开~/.vimrc,在文件头加入以下内容
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle
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 - 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-
从其中的注释可以知道,Vundle支持多种形式的插件源,并给出了示例。这些插件源包括:github上的插件、http://vim-scripts.org/vim/scripts.html上的插件、非github上的git插件、本地硬盘上的插件等。
- 打开vim,运行 :PluginInstall 命令来自动安装插件,过程中有可能需要输入github用户名和密码。等待Vundle安装完成即可。
Vundle正在自动安装在.vimrc中指定的插件:
2、Doxygen注释自动生成
为自己的代码写好注释是一个良好的习惯,而编写Doxygen风格的注释更是可以通过doxygen工具为代码自己生成文档,非常好用。DoxygenToolkit(https://github.com/vim-scripts/DoxygenToolkit.vim)就是这样的一个插件。安装和使用:
- 在~/.vimrc中的Vundle插件列表区域中添加DoxygenToolkit的源位置
Plugin 'vim-scripts/DoxygenToolkit.vim'
保存后退出,再打开vim,运行:PluginInstall命令安装 - 在~.vimrc中,Vundle区域后的某处,设置DoxygenToolkit插件在@author区域自动填充的作者名称,比如
let g:DoxygenToolkit_authorName="author"
- 使用时,将光标定位到文件首行,输入:DoxAuthor将插入文件头注释骨架(第一次会让你输入文件版本号);
- 并把光标停留在@brief 后面,等待输入文件描述。在光标定位到数据结构声明或函数声明的第一行,运行:Dox,将生成数据结构或函数的注释骨架;
3、nerdtree树形目录
在.vimrc中加入
Bundle 'The-NERD-tree'
Bundle 'The-NERD-Commenter'
然后执行
vim
然后执行安装命令
:BundleInstall
使用命令
:NERDTree 进入树形界面
:NERDTreeToggle 关闭树形
设置默认开启 .vimrc中添加 autocmd VimEnter * NERDTree
显示与隐藏
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>
常用命令
和编辑文件一样,通过h j k l移动光标定位
打开关闭文件或者目录,如果是文件的话,光标出现在打开的文件中
go 效果同上,不过光标保持在文件目录里,类似预览文件内容的功能
i和s可以水平分割或纵向分割窗口打开文件,前面加g类似go的功能
t 在标签页中打开
T 在后台标签页中打开
ctrl+w+w 光标在左右窗口切换
ctrl+w+r 切换当前窗口左右布局
ctrl+p 模糊搜索文件
gT 切换到前一个tab
g t 切换到后一个tab
p 到上层目录
P 到根目录
K 到同目录第一个节点
J 到同目录最后一个节点
m 显示文件系统菜单(添加、删除、移动操作)
r: 刷新光标所在的目录
R: 刷新当前根路径
? 帮助
q 关闭
参考: