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。稍后我们讲解详细设置。
安装:
- $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的源码文件夹下使用
- $ctags -R ./*
建立好了tags文件,但是ta一次之后就无法再次使用tags文件了,这是因为我们进入了子目录中vi无法知晓tags文件所在,所以我们加上递归的调用(特别注意 分号不能丢)
- set tags=tags;
- set autochdir
2.多个tags文件,我在自动补全的时候,不光有我自己定义的头文件中所包含的数据结构需要提示,像STL库中的一些数据结构也需要提示,如是我先建立了一个stl_tags放在~/.vim/tags/中
设置 set tags=./tags,tags,~/.vim/tags/stl_tags;
这样就能载入多个tags文件了
最后附上我的简单vimrc配置文件
- if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
- let g:iswindows=1
- else
- let g:iswindows=0
- endif
- autocmd BufEnter * lcd %:p:h
- set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题
- syntax on"打开高亮
- if has("autocmd")
- filetype plugin indent on "根据文件进行缩进
- augroup vimrcEx
- au!
- autocmd FileType text setlocal textwidth=78
- autocmd BufReadPost *
- \ if line("'\"") > 1 && line("'\"") <= line("$") |
- \ exe "normal! g`\"" |
- \ endif
- augroup END
- else
- "智能缩进,相应的有cindent,官方说autoindent可以支持各种文件的缩进,但是效果会比只支持C/C++的cindent效果会差一点,但笔者并没有看出来
- set autoindent " always set autoindenting on
- endif " has("autocmd")
- "set tabstop=4 "让一个tab等于4个空格
- set vb t_vb=
- set number "show line number
- set title "show file name as title of this console
- set nowrap "不自动换行
- set hlsearch "高亮显示结果
- set incsearch "在输入要搜索的文字时,vim会实时匹配
- set backspace=indent,eol,start whichwrap+=<,>,[,] "允许退格键的使用
- if(g:iswindows==1) "允许鼠标的使用
- "防止linux终端下无法拷贝
- if has('mouse')
- set mouse=a
- endif
- au GUIEnter * simalt ~x
- endif
- "字体的设置
- set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI "记住空格用下划线代替哦
- set gfw=幼圆:h10:cGB2312
- "检查ctags,cscope是否安装并设置到环境变量中
- "生成最新的cscope.out使omnicppcomplete能起效
- "check if ctags&cscope installed and added into path
- map <F12> :call Do_CsTag()<CR>
- nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
- nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
- nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
- nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
- function Do_CsTag()
- let dir = getcwd()
- if filereadable("tags")
- if(g:iswindows==1)
- let tagsdeleted=delete(dir."\\"."tags")
- else
- let tagsdeleted=delete("./"."tags")
- endif
- if(tagsdeleted!=0)
- echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
- return
- endif
- endif
- if has("cscope")
- silent! execute "cs kill -1"
- endif
- if filereadable("cscope.files")
- if(g:iswindows==1)
- let csfilesdeleted=delete(dir."\\"."cscope.files")
- else
- let csfilesdeleted=delete("./"."cscope.files")
- endif
- if(csfilesdeleted!=0)
- echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
- return
- endif
- endif
- if filereadable("cscope.out")
- if(g:iswindows==1)
- let csoutdeleted=delete(dir."\\"."cscope.out")
- else
- let csoutdeleted=delete("./"."cscope.out")
- endif
- if(csoutdeleted!=0)
- echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
- return
- endif
- endif
- if(executable('ctags'))
- "silent! execute "!ctags -R --c-types=+p --fields=+S *"
- silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
- endif
- if(executable('cscope') && has("cscope") )
- if(g:iswindows!=1)
- silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
- else
- silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
- endif
- silent! execute "!cscope -b"
- execute "normal :"
- if filereadable("cscope.out")
- execute "cs add cscope.out"
- endif
- endif
- endfunction
- "close omnicppcomplete preview window
- "关闭omnicppcomplete预览窗口
- set completeopt=menu
- "进行Tlist设置
- "taglist settings
- "TlistUpdate can update tags
- "TlistUpdate可以更新tags
- map <F3> :silent! Tlist<CR> "按下F3就可以呼出了
- let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
- let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边
- let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表,
- "如果想只有1个,设置为1
- let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
- let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
- let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理。不是一直实时更新tags,因为没有必要
- let Tlist_Inc_Winwidth=0
- "setting nerdcommenter
- "对nerdcommenter设置
- let NERDShutUp=1
- "setting comment shortcut
- "<leader> + cc set comment
- "<leader> + cu unset comment
- let mapleader="`"
- "setting doxygentoolit
- map fg : Dox<cr>
- let g:DoxygenToolkit_authorName="qingluo"
- let g:DoxygenToolkit_licenseTag="qingluo's own license\<enter>"
- let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
- let g:DoxygenToolkit_briefTag_pre = "@brief\t"
- let g:DoxygenToolkit_paramTag_pre = "@param\t"
- let g:DoxygenToolkit_returnTag = "@return\t"
- let g:DoxygenToolkit_briefTag_funcName = "no"
- let g:DoxygenToolkit_maxFunctionProtoLines = 30
- "setting ctags files
- set tags=tags,./tags,/root/.vim/tags/tags_kernelapi;
- set autochdir
- "color setting