vim 插件配置博客记录

来源:互联网 发布:易语言大话西游源码 编辑:程序博客网 时间:2024/06/14 00:47

本来打算自己写下各种常用vim的插件安装方法, 但是搜索了下, 发现别人都写过了, 在写一遍也没有意思, 特此记录.


  • Vim 常用命令

http://blog.csdn.net/hittata/article/details/8096697

命令 含义 % 跳转到配对的括号去{} [[ 向前跳转到{代码块的开头处 ]] 向后跳转到}代码块的结尾处 gD 跳转到局部变量的定义处 gg 跳转到文件开头 G 跳转到文件末尾 > 增加缩进,”x>”表示增加以下x行的缩进 < 减少缩进,”x<”表示减少以下x行的缩进 # 查找光标所在单词(先前) * 查找光标所在单词(向后) 0 硬行首,纯粹行首第一个字符 ^ 软行首,忽略掉空格的行首 $ 行尾 + 下一行行首,忽略掉空格的行首 - 上一行行首,忽略掉空格的行首 / 向后查找 ? 向前查找 n 查找下一个 N 查找上一个 w 光标移到下一个单词 b 光标移到上一个单词 E 或e 光标移动到词尾 ” 跳转到光标上次停靠的地方,是两个’, 而不是一个”
  • 基本配置
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 显示相关  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""set shortmess=atI   " 启动的时候不显示那个援助乌干达儿童的提示  "winpos 5 5          " 设定窗口位置  "set lines=40 columns=155    " 设定窗口大小  "set nu              " 显示行号  set go=             " 不要图形按钮  color dark     " 设置背景主题   syntax on           " 语法高亮  autocmd InsertLeave * se nocul  " 用浅色高亮当前行  autocmd InsertEnter * se cul    " 用浅色高亮当前行  "set ruler           " 显示标尺  set showcmd         " 输入的命令显示出来,看的清楚些  "set cmdheight=1     " 命令行(在状态行下)的高度,设置为1  "set whichwrap+=<,>,h,l   " 允许backspace和光标键跨越行边界(不建议)  "set scrolloff=3     " 光标移动到buffer的顶部和底部时保持3行距离  set novisualbell    " 不要闪烁(不明白)  set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}   "状态行显示的内容  set laststatus=1    " 启动显示状态行(1),总是显示状态行(2)  set foldenable      " 允许折叠  set foldmethod=manual   " 手动折叠  "set background=dark "背景使用黑色 set nocompatible  "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限  " 显示中文帮助if version >= 603    set helplang=cn    set encoding=utf-8endif" 设置配色方案colorscheme desert" 设置字体和字号set guifont=Consolas\ 18" 不要使用vi的键盘模式,而是vim自己的set nocompatible" 语法高亮set syntax=on" 去掉输入错误的提示声音set noeb" 在处理未保存或只读文件的时候,弹出确认set confirm" 自动缩进set autoindentset cindent" Tab键的宽度set tabstop=4" 统一缩进为4set softtabstop=4set shiftwidth=4" 不要用空格代替制表符set noexpandtab" 在行和段开始处使用制表符set smarttab" 显示行号set number" 历史记录数set history=1000"禁止生成临时文件set nobackupset noswapfile"搜索忽略大小写set ignorecase"搜索逐字符高亮set hlsearchset incsearch"行内替换set gdefault"编码设置set enc=utf-8set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936"语言设置set langmenu=zh_CN.UTF-8set helplang=cn" 我的状态行显示的内容(包括文件类型和解码)"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]" 总是显示状态行set laststatus=2" 命令行(在状态行下)的高度,默认为1,这里是2set cmdheight=2" 侦测文件类型filetype on" 载入文件类型插件filetype plugin on" 为特定文件类型载入相关缩进文件filetype indent on" 保存全局变量set viminfo+=!" 带有如下符号的单词不要被换行分割set iskeyword+=_,$,@,%,#,-" 字符间插入的像素行数目set linespace=0" 增强模式中的命令行自动完成操作set wildmenu" 使回格键(backspace)正常处理indent, eol, start等set backspace=2" 允许backspace和光标键跨越行边界set whichwrap+=<,>,h,l" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)set mouse=aset selection=exclusiveset selectmode=mouse,key" 通过使用: commands命令,告诉我们文件的哪一行被改变过set report=0" 在被分割的窗口间显示空白,便于阅读set fillchars=vert:\ ,stl:\ ,stlnc:\" 高亮显示匹配的括号set showmatch" 匹配括号高亮的时间(单位是十分之一秒)set matchtime=1" 光标移动到buffer的顶部和底部时保持3行距离set scrolloff=3" 为C程序提供自动缩进set smartindent" 高亮显示普通txt文件(需要txt.vim脚本)au BufRead,BufNewFile *  setfiletype txt 

  • vim miniBufexplorer 打开的文件缓存浏览器

http://blog.csdn.net/hittata/article/details/8097805

  1. miniBufexplorer 为vim插件,直接解压拷贝到相关目录即可,
    下载官方地址:
    http://www.vim.org/scripts/script.php?script_id=159
    minibufexpl.vim
    minibufexpl.vim 拷贝到 $HOME/.vim/plugin目录下

  2. $HOME/.vimrc 中添加如下配置

        let g:miniBufExplMapWindowNavVim = 1     let g:miniBufExplMapWindowNavArrows = 1     let g:miniBufExplMapCTabSwitchBufs = 1     let g:miniBufExplModSelTarget = 1
  3. 解决FileExplorer窗口变小问题 须在$HOME/.vimrc中添加:
    “解决FileExplorer窗口变小问题

    let g:bufExplorerMaxHeight=30let g:miniBufExplorerMoreThanOne=0

  • NertTree 文件目录树

http://www.cnblogs.com/feichexia/archive/2012/11/07/Vim_NerdTree.html

从 http://www.vim.org/scripts/script.php?script_id=1658 下载,然后解压,将解压得到的plugin和doc文件夹与HOME/.vimHOME/.vimrc文件中增加下面配置代码:

” 设置NerdTree

    map <F3> :NERDTreeMirror<CR>    map <F3> :NERDTreeToggle<CR>

按F3即可显示或隐藏NerdTree区域了。

如果你不喜欢目录树在左边, 可以添加

    let NERDTreeWinPos  = "right"

  • TagBar 函数(变量)列表

tagbar是一个taglist的替代品,比taglist更适合c++使用,函数能够按类区分,支持按类折叠显示等,显示结果清晰简洁,强烈推荐,下载地址如下:
http://www.vim.org/scripts/script.php?script_id=3465

安装方式 :

 vim tagbar.vba    :so %    :q

快捷键打开/关闭

    nnoremap <silent> <F3> :TagbarToggle<CR>

设置属性

    let g:tagbar_width = 30     let g:tagbar_left = 1 

添加你自己的tags文件

    set tags+= xxx

在vim下执行 :

:!ctags -R *

然后就可以通过G来跳转到对应的定义处了。


cscope 跳转

一 下载安装
1. 检测是否

vim --version |grep cscope+cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic 
  1. 下载:cscope 源码
    http://cscope.sourceforge.net/
    http://sourceforge.net/projects/cscope/files/cscope/
  2. 安装:
    如未安装flex,需要先安装flex

    yum install flex./configuremakemake install```

    上述不行,使用下面命令:

    make distclean./configure --with-flexmake

    二 生成cscope文件列表和数据库:

生成脚本:

#!/bin/bash  echo "Begin TO Generage cscope.files..."  find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files  ls -l  cscope.files  echo "Begin TO Generage cscope.out"  cscope -Rbq -i cscope.files -I /usr/local/mysql/include  ls -l  cscope.*  echo "Begin TO Generage tags"  ctags -R  ls -l tags   echo "Complete Successfully"  

cscope 选项说明:-I选项将自己要包含的头文件添加进去。

-R: 在生成索引文件时,搜索子目录树中的代码-b: 只生成索引文件,不进入cscope的界面-k: 在生成索引文件时,不搜索/usr/include目录-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度-i: 如果保存文件列表的文件名不是cscope.files时,需要加此选项告诉cscope到哪儿去找源文件列表。可以使用“-”,表示由标准输入获得文件列表。-I dir: 在-I选项指出的目录中查找头文件-u: 扫描所有文件,重新生成交叉索引文件-C: 在搜索时忽略大小写-P path: 在以相对路径表示的文件前加上的path,这样,你不用切换到你数据库文件所在的目录也可以使用它了。-I 选项非常有用,用于将其他开发库头文件导入到cscope数据库,方便产看,开发;

三.cscope 与vim 集成设置:
需要在.vimrc中添加如下配置

""""""""""""""""""""""""""""""  " Cscope Config  """"""""""""""""""""""""""""""  nmap <S-F10> :!creat_cscope<CR>nmap <S-F11> :cs add cscope.out<CR>nmap <A-F> :cs find s <C-R>=expand("<cword>")<CR><CR>  nmap csg :cs find g <C-R>=expand("<cword>")<CR><CR>  nmap csc :cs find c <C-R>=expand("<cword>")<CR><CR>  nmap cst :cs find t <C-R>=expand("<cword>")<CR><CR>  nmap cse :cs find e <C-R>=expand("<cword>")<CR><CR>  nmap csf :cs find f <C-R>=expand("<cfile>")<CR><CR>  nmap csi :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  nmap csd :cs find d <C-R>=expand("<cword>")<CR><CR> "-------------------------------- Cscope -------------------------------------------" Using 'Control-\ + key' makes the vim window split vertically," with search result displayed in the window" 's' symbol: find all references to the token under cursornnoremap <C-\>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>" 'g' global: find global definition(s) of the token under cursornnoremap <C-\>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>" 'c' calls: find all calls to the function name under cursornnoremap <C-\>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>" 't' text: find all instances of the text under cursornnoremap <C-\>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>" 'e' egrep: egrep search for the word under cursornnoremap <C-\>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>" 'f' file: open the filename under cursornnoremap <C-\>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>" 'i' includes: find files that include the filename under cursornnoremap <C-\>i :vert scs find i <C-R>=expand("<cfile>")<CR><CR>" 'd' called: find functions that function under cursor callsnnoremap <C-\>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>" using 'alt+key' search result in a new buffer" we cannot use <A-key> to map 'alt-key' directly in terminal" because when press alt in terminal it will be translated to <Esc>" I use set to combine the 'alt-key' to a virtual multi-byte character" which  first byte is <Esc> (like F1), and the benefit is ttimeoutlen" affect it instead of timeoulenif has("gui_running")    " disable alt key in gvim to make our mapping working    set guioptions-=melse     set <M-f>=f    set <M-g>=g    set <M-t>=t    set <M-c>=c    set <M-e>=e    set <M-o>=o    set <M-i>=i    set <M-d>=dendif" I use alt-f to map 'find s' to keep my habit on windows" then i must use alt-o not alt-f to map 'find f'nnoremap <M-f> :cs find s <C-R>=expand("<cword>")<CR><CR>nnoremap <M-g> :cs find g <C-R>=expand("<cword>")<CR><CR>nnoremap <M-c> :cs find c <C-R>=expand("<cword>")<CR><CR>nnoremap <M-t> :cs find t <C-R>=expand("<cword>")<CR><CR>nnoremap <M-e> :cs find e <C-R>=expand("<cword>")<CR><CR>nnoremap <M-o> :cs find f <C-R>=expand("<cfile>")<CR><CR>nnoremap <M-i> :cs find i <C-R>=expand("<cfile>")<CR><CR>nnoremap <M-d> :cs find d <C-R>=expand("<cword>")<CR><CR>

四.cscope 和 quickfix使用
:cs find 的选项

0或则S:查找本符号1或则G:查找本定义2或则D:查找本函数调用的函数3或则C:查找调用本函数的函数4或则T:查找本字符串6或则E:查找本EGREP模式7或则F:查找本文件8或则I:查找包含本文件的文件

quickfix用法:

1.调出办法  :cw   2.关闭办法 再一次:cw   或者在激活状态下:q3.显示列表移动:cn // 切换到下一个结果:cp // 切换到上一个结果

  • Mark 单词高亮

http://www.2cto.com/os/201208/148806.html

下载

http://www.vim.org/scripts/script.php?script_id=1238

高亮的使用方法:

Normal mode:

    Vim的Normal mode中,    \m 用来使得光标处的单词着色    \n 使得原先着色的单词取消着色    \r  输入\r后再输入正则表达式,可以高亮匹配的相关单词

关闭swap 缓存! 这样多个vim打开同一个文件就没有警告了。

" ---- no swap file set nobackupset noswapfileset nowritebackup

clewn 进行DEBUG 配置。

"-------------- clewn ------------"------------------------------------ clewn  ----------------------------------------"add break pointnmap <silent> <C-B> :nbkey C-B<CR>"clear break pointnmap <silent> <C-E> :nbkey C-E<CR>"next source line, skipping all function callsnmap <silent> <F10> :nbkey C-N<CR>"step intonmap <silent> <F11> :nbkey S-S<CR>"step outnmap <silent> <F12> :nbkey S-F<CR>"continuenmap <silent> <F5> :nbkey S-C<CR>



如果你看到这里 , 说明你对上面的东西不慎满意 , 没关系 , 下面这个还有一个博客

http://ju.outofmemory.cn/entry/79671

希望能满足你 .

1 0