安装若干 VIM 插件(不断更新)

来源:互联网 发布:别墅网络布线 ac ap 编辑:程序博客网 时间:2024/05/21 06:46

本文中的插件信息, 大部分来自 https://github.com/yangyangwithgnu/use_vim_as_ide

在此向作者致敬


先安装插件管理工具 pathogen


创建目录 ~/.vim/bundle/pathogen/autoload/

下载 pathogen.vim(https://github.com/tpope/vim-pathogen )至 ~/.vim/bundle/pathogen/autoload/

在 .vimrc 中加入下面两行

runtime bundle/pathogen/autoload/pathogen.vim
execute pathogen#infect()


其他插件下载解压后, 都拷贝到 ~/.vim/bundle/ 目录下即可


书签插件
https://github.com/huxiao/vim-bookmark

插件的基本用法:

mm 用于设定或者删除一个书签,或者使用命令 VbookmarkToggle
mn 用于跳转到下一个书签,或者使用命令 VbookmarkNext
mp 用于跳转到前一个书签,或者使用命令 VbookmarkPrevious

ma 用于删除所有书签,或者使用命令 VbookmarkClearAll


let g:vbookmark_bookmarkSaveFile = $HOME . '/.vimbookmark'

" 设置跳转书签的快捷键

" nmap <F2> mn

nmap <F2> :w<CR>mn

imap <F2> <ESC>:w<CR>




C++ STL 语法高亮插件

https://github.com/octol/vim-cpp-enhanced-highlight 



*.cpp 和 *.h 间切换

a.vim(https://github.com/vim-scripts/a.vim )来了。安装后增加配置信息:

" *.cpp 和 *.h 间切换
nmap <Leader>ch :A<CR>
" 子窗口中显示 *.cpp 或 *.h
nmap <Leader>chv :AV<CR>

这样,键入 ;ch 就能在实现文件和接口文件间切换,键入 ;chv 子窗口中将显示实现文件/接口文件


快速开关注释
NERD Commenter(https://github.com/scrooloose/nerdcommenter )

常用操作:

<leader>cc,注释当前选中文本,如果选中的是整行则在每行首添加 //,如果选中一行的部分内容则在选中部分前后添加分别 /、/;

<leader>cu,取消选中文本块的注释。

也可以都调用 <leader>c<SPACE> ,它会根据是否有注释而选择来注释还是取消注释。


括号引号自动补全

https://github.com/Raimondi/delimitMate


or


https://github.com/jiangmiao/auto-pairs


工程文件浏览

NERDtree (https://github.com/scrooloose/nerdtree )

将如下信息加入.vimrc中:

" 使用 NERDTree 插件查看工程文件。设置快捷键
nmap <F8> :NERDTreeToggle<CR>
" 设置NERDTree子窗口宽度let NERDTreeWinSize=32" 设置NERDTree子窗口位置let NERDTreeWinPos="right"" 显示隐藏文件let NERDTreeShowHidden=1" NERDTree 子窗口中不显示冗余帮助信息let NERDTreeMinimalUI=1" 删除文件时自动删除文件对应 bufferlet NERDTreeAutoDeleteBuffer=1
常用操作:回车,打开选中文件;r,刷新工程目录文件列表;I(大写),显示/隐藏隐藏文件;m,出现创建/删除/剪切/拷贝操作列表。键入 <leader>fl 后,右边子窗口为工程项目文件列表


ctags

http://ctags.sourceforge.net/ 下载源代码包后,解压缩生成源代码目录,然后进入源代码根目录执行./configure,然后执行make,编译成功后执行make install

在 .vimrc 中加入以下设置

nmap<leader>R :!ctags -R<CR>

这样, 在 VIM 中按 <leader> + r 就可以生成当前目录的 tags 文件了



根据头文件中的函数声明,自动生成 CPP 文件中的空白函数体

ProtoDef (http://www.vim.org/scripts/script.php?script_id=2624 )

ProtoDef 需要依赖 perl , ctags 和 FSwitch(http://www.vim.org/scripts/script.php?script_id=2590 )

安装好 ProtoDef 后, 在 .vimrc 中加入以下配置

" 设置 pullproto.pl 脚本路径let g:protodefprotogetter='~/.vim/bundle/protodef/pullproto.pl'" 成员函数的实现顺序与声明顺序一致let g:disable_protodef_sorting=1

使用的时候, 先在源码目录使用 ctags -R 命令生成 tags 文件; 然后在 .h 文件中声明类函数, 切换到同名 .cpp 文件中后, 键入 <leader>PP 即可补全函数空白体


内容查找

ctrlsf.vim(https://github.com/dyng/ctrlsf.vim )


需要事先安装 ack
sudo apt-get install ack-grep

安装 ag

sudo apt-get install silversearcher-ag

https://github.com/rking/ag.vim


在 .vimrc 中加入以下配置

" 使用 ctrlsf.vim 插件在工程内全局查找光标所在关键字,设置快捷键。快捷键速记法:search in projectnnoremap <leader>sp :CtrlSF<CR>
noremap <leader>? :CtrlSF -R
nmap <F4> :CtrlSFToggle<CR>
noremap <leader>/ :silent execute("CtrlSF -R '\\b" . expand("<cword>") . "\\b'")<CR>
let g:ctrlsf_ackprg = 'ag' "设置 ctrlsf 使用 ag
" ag 快捷键
noremap <leader>f :silent execute("Ag " . expand("<cword>"))<CR>





语法检测

syntastic ( https://github.com/scrooloose/syntastic )

 在 .vimrc 中加入以下配置

let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
" 是否在打开文件时检查
let g:syntastic_check_on_open=0
" 是否在保存文件后检查
let g:syntastic_check_on_wq=1


内容替换


将完整配置信息添加进 .vimrc 中:

" 替换函数。参数说明:" confirm:是否替换前逐一确认" wholeword:是否整词匹配" replace:被替换字符串function! Replace(confirm, wholeword, replace)    wa    let flag = ''    if a:confirm        let flag .= 'gec'    else        let flag .= 'ge'    endif    let search = ''    if a:wholeword        let search .= '\<' . escape(expand('<cword>'), '/\.*$^~[') . '\>'    else        let search .= expand('<cword>')    endif    let replace = escape(a:replace, '/\&~')    execute 'argdo %s/' . search . '/' . replace . '/' . flag . '| update'endfunction" 不确认、非整词"nnoremap <Leader>R :call Replace(0, 0, input('Replace '.expand('<cword>').' with: '))<CR>" 不确认、整词nnoremap <Leader>rw :call Replace(0, 1, input('Replace '.expand('<cword>').' with: '))<CR>" 确认、非整词"nnoremap <Leader>rc :call Replace(1, 0, input('Replace '.expand('<cword>').' with: '))<CR>" 确认、整词"nnoremap <Leader>rcw :call Replace(1, 1, input('Replace '.expand('<cword>').' with: '))<CR>"nnoremap <Leader>rwc :call Replace(1, 1, input('Replace '.expand('<cword>').' with: '))<CR>




文件查找

ctrlp ------ https://github.com/kien/ctrlp.vim

map <leader>p :CtrlPMRU<CR> "模糊搜索最近打开的文件

查看函数,结构体,变量列表

tagbar ------ https://github.com/majutsushi/tagbar


 " 设置标签子窗口的宽度 
let tagbar_width=32 
" tagbar 子窗口中不显示冗余帮助信息 
let g:tagbar_compact=1


// GO 语言配置

let g:tagbar_type_go = {

    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }


// c++ 语言配置
" 设置 ctags 对哪些代码元素生成标签
let g:tagbar_type_cpp = {
\ 'kinds' : [
\ 'd:macros:1',
\ 'g:enums',
\ 't:typedefs:0:0',
\ 'e:enumerators:0:0',
\ 'n:namespaces',
\ 'c:classes',
\ 's:structs',
\ 'u:unions',
\ 'f:functions',
\ 'm:members:0:0',
\ 'v:global:0:0',
\ 'x:external:0:0',
\ 'l:local:0:0'
 \ ],
 \ 'sro' : '::',
 \ 'kind2scope' : {
 \ 'g' : 'enum',
 \ 'n' : 'namespace',
 \ 'c' : 'class',
 \ 's' : 'struct',
 \ 'u' : 'union'
 \ },
 \ 'scope2kind' : {
 \ 'enum'   : 'g',
 \ 'namespace' : 'n',
 \ 'class'  : 'c',
 \ 'struct' : 's',
 \ 'union'  : 'u'
 \ }
\ } 


nmap <F3> :TagbarToggle<CR>


任务列表 
https://github.com/vim-scripts/TaskList.vim

这是一个非常有用的插件,它能够标记文件中的 FIXME 、 TODO 等信息,并将它们存放到一个任务列表当中,后面随时可以通过Tasklist跳转到这些标记的地方再来修改这些代码,是一个十分方便实用的Todo list工具。

--help: 通常只需添加一个映射: map <leader>td <Plug>TaskList


多光标输入 
vim-multiple-cursors
https://github.com/terryma/vim-multiple-cursors
在普通模式下,按下 Ctrl - n 开始进入可视模式并选中光标下的单词,继续按 Ctrl - n 选择下一个相同的单词,按下 Ctrl - p 往回选一个, Ctrl - x 则跳过下一个相同单词. 按下 c 进行修改,  按下 <Esc> 退出


0 0