vim配置及使用

 vim与emacs是2个非常牛B的编辑器,甚至是IDE,甚至是伪系统!emacs还没深入去学习。先讲讲最近配置vim的心得吧!

vim建议先将基本的操作命令用熟再进行配置插件,不然不会走就想跑,肯定要摔跤。

vim的插件我仅装了几个taglist, a.vim, doxygentoolkit.vim, Nerd_commenter.vim nomicppcomplete.vim

依赖的应用程序ctags cscope

a.vim  在xxx.c与xxx.h之间进行相互切换

使用命令为 :A  :AV

DoxygenToolkit.vim 自动填充文件注释

命令 :Dox 生成接口函数注释

:DoxAuthor 生成作者信息等文件注释

:DoxLic 生成协议注释

Nerd_commenter.vim 快速行块注释

<control> cc 快速注释当前选中行或块

<control> cu 快速取消注释,这里的<control>我设置的是~按键,你可以设置成你想要的不影响其他功能的按键。

omnicppcomplete.vim 自动补全及提示,主要依赖于ctags与cscope。稍后我们讲解详细设置。

安装:

  
  
  
  
  1. $yum install ctags cscope -y 

几个.vim插件请到vim官网上下载,大多数都给出了安装方法,这里只小提一下

有3个主要安装路径

/usr/share/vim/vim72 除了omnicppcomplete.vim 其他插件都可以通过

unzip xxx.vim -d /usr/share/vim/vim72 来进行导入

/usr/share/vim/vimfile  omnicppcomplete.vim

unzip omnicppcomplete.vim -d /usr/share/vim/vimfile 来进行导入

~/.vim/ 若没有自行创建

这3者的区分就是影响范围不同,建议都安装到~/.vim中(我的是ubuntu 所以安装到此处)。

特别介绍一个强大的窗口管理工具 tmux,他可以让运维及远程ssh变得简单方便。我最看重他的一点就是他的helpprogramming功能

相关使用介绍视频链接:http://happycasts.net/episodes/41

vim的配置参考自:www.vimer.cn。

感谢各位大大的无私分享。

我在ctags的使用中主要存在2大问题。ctags文件递归查找访问,多个tags文件同时使用。

1.我在linux的源码文件夹下使用

  
  
  
  
  1. $ctags -R ./* 

建立好了tags文件,但是ta一次之后就无法再次使用tags文件了,这是因为我们进入了子目录中vi无法知晓tags文件所在,所以我们加上递归的调用(特别注意 分号不能丢)

  
  
  
  
  1. set tags=tags; 
  2. set autochdir 

2.多个tags文件,我在自动补全的时候,不光有我自己定义的头文件中所包含的数据结构需要提示,像STL库中的一些数据结构也需要提示,如是我先建立了一个stl_tags放在~/.vim/tags/中

设置 set tags=./tags,tags,~/.vim/tags/stl_tags;

这样就能载入多个tags文件了

 

最后附上我的简单vimrc配置文件

  
  
  
  
  1. if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型 
  2.     let g:iswindows=1 
  3. else 
  4.     let g:iswindows=0 
  5. endif 
  6. autocmd BufEnter * lcd %:p:h 
  7. set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题 
  8. syntax on"打开高亮 
  9. if has("autocmd"
  10.     filetype plugin indent on "根据文件进行缩进 
  11.     augroup vimrcEx 
  12.         au! 
  13.         autocmd FileType text setlocal textwidth=78 
  14.         autocmd BufReadPost * 
  15.                     \ if line("'\"") > 1 && line("'\"") <= line("$") | 
  16.                     \ exe "normal! g`\"" | 
  17.                     \ endif 
  18.     augroup END 
  19. else 
  20.     "智能缩进,相应的有cindent,官方说autoindent可以支持各种文件的缩进,但是效果会比只支持C/C++的cindent效果会差一点,但笔者并没有看出来 
  21.     set autoindent " always set autoindenting on  
  22. endif " has("autocmd") 
  23. "set tabstop=4 "让一个tab等于4个空格 
  24. set vb t_vb= 
  25. set number "show line number 
  26. set title  "show file name as title of this console 
  27. set nowrap "不自动换行 
  28. set hlsearch "高亮显示结果 
  29. set incsearch "在输入要搜索的文字时,vim会实时匹配 
  30. set backspace=indent,eol,start whichwrap+=<,>,[,] "允许退格键的使用 
  31. if(g:iswindows==1) "允许鼠标的使用 
  32.     "防止linux终端下无法拷贝 
  33.     if has('mouse'
  34.         set mouse=a 
  35.     endif 
  36.     au GUIEnter * simalt ~x 
  37. endif 
  38. "字体的设置 
  39. set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI "记住空格用下划线代替哦 
  40. set gfw=幼圆:h10:cGB2312 
  41.  
  42. "检查ctags,cscope是否安装并设置到环境变量中 
  43. "生成最新的cscope.out使omnicppcomplete能起效 
  44. "check if ctags&cscope installed and added into path 
  45. map <F12> :call Do_CsTag()<CR> 
  46. nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR> 
  47. nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR> 
  48. nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR> 
  49. nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR> 
  50. nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR> 
  51. nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR> 
  52. nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR> 
  53. nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR> 
  54. function Do_CsTag() 
  55.     let dir = getcwd() 
  56.     if filereadable("tags"
  57.         if(g:iswindows==1) 
  58.             let tagsdeleted=delete(dir."\\"."tags") 
  59.         else 
  60.             let tagsdeleted=delete("./"."tags"
  61.         endif 
  62.         if(tagsdeleted!=0) 
  63.             echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None 
  64.             return 
  65.         endif 
  66.     endif 
  67.     if has("cscope"
  68.         silent! execute "cs kill -1" 
  69.     endif 
  70.     if filereadable("cscope.files"
  71.         if(g:iswindows==1) 
  72.             let csfilesdeleted=delete(dir."\\"."cscope.files") 
  73.         else 
  74.             let csfilesdeleted=delete("./"."cscope.files"
  75.         endif 
  76.         if(csfilesdeleted!=0) 
  77.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None 
  78.             return 
  79.         endif 
  80.     endif 
  81.     if filereadable("cscope.out"
  82.         if(g:iswindows==1) 
  83.             let csoutdeleted=delete(dir."\\"."cscope.out") 
  84.         else 
  85.             let csoutdeleted=delete("./"."cscope.out"
  86.         endif 
  87.         if(csoutdeleted!=0) 
  88.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None 
  89.             return 
  90.         endif 
  91.     endif 
  92.     if(executable('ctags')) 
  93.         "silent! execute "!ctags -R --c-types=+p --fields=+S *" 
  94.         silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ." 
  95.     endif 
  96.     if(executable('cscope') && has("cscope") ) 
  97.         if(g:iswindows!=1) 
  98.             silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files" 
  99.         else 
  100.             silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files" 
  101.         endif 
  102.         silent! execute "!cscope -b" 
  103.         execute "normal :" 
  104.         if filereadable("cscope.out"
  105.             execute "cs add cscope.out" 
  106.         endif 
  107.     endif 
  108. endfunction 
  109. "close omnicppcomplete preview window 
  110. "关闭omnicppcomplete预览窗口 
  111. set completeopt=menu 
  112.  
  113. "进行Tlist设置  
  114. "taglist settings 
  115. "TlistUpdate can update tags 
  116. "TlistUpdate可以更新tags 
  117. map <F3> :silent! Tlist<CR> "按下F3就可以呼出了 
  118. let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行 
  119. let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边 
  120. let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表, 
  121.                 "如果想只有1个,设置为1 
  122. let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏 
  123. let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim 
  124. let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理。不是一直实时更新tags,因为没有必要 
  125. let Tlist_Inc_Winwidth=0 
  126.  
  127. "setting nerdcommenter 
  128. "对nerdcommenter设置 
  129. let NERDShutUp=1 
  130. "setting comment shortcut 
  131. "<leader> + cc set comment 
  132. "<leader> + cu unset comment 
  133. let mapleader="`" 
  134.  
  135. "setting doxygentoolit 
  136. map fg : Dox<cr> 
  137. let g:DoxygenToolkit_authorName="qingluo" 
  138. let g:DoxygenToolkit_licenseTag="qingluo's own license\<enter>" 
  139. let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK" 
  140. let g:DoxygenToolkit_briefTag_pre = "@brief\t" 
  141. let g:DoxygenToolkit_paramTag_pre = "@param\t" 
  142. let g:DoxygenToolkit_returnTag = "@return\t" 
  143. let g:DoxygenToolkit_briefTag_funcName = "no" 
  144. let g:DoxygenToolkit_maxFunctionProtoLines = 30 
  145.  
  146. "setting ctags files 
  147. set tags=tags,./tags,/root/.vim/tags/tags_kernelapi; 
  148. set autochdir 
  149. "color setting 

 

你可能感兴趣的:(vim,tmux,vimrc)