vim初学配置笔记 vimrc 清疚 2021-12-19 05:29 261阅读 0赞 (在vimtuor后继续的学习性况笔记 下一步完整的照着帮助文档看练习一遍,并整合gdb进去) 初学VIM的vimrc配置情况 主要是拿来用c/c++的 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "中文 set helplang=cn "utf-8编码 set encoding=utf-8 "语法高亮 syntax enable syntax on colorscheme desert "设置(软)制表符宽度为4: set tabstop=4 set softtabstop=4 "设置缩进的空格数为4 set shiftwidth=4 "设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置: set autoindent "设置使用 C/C++ 语言的自动缩进方式: set cindent "设置C/C++语言的具体缩进方式(以我的windows风格为例): set cinoptions=\{0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "如果想在左侧显示文本的行号,可以用以下语句: set nu "最后,如果没有下列语句,就加上吧: if &term=="xterm" set t\_Co=8 set t\_Sb=^\[\[4%dm set t\_Sf=^\[\[3%dm endif "taglist 插件Ctags 插件: TagList let Tlist\_Show\_One\_File=1 let Tlist\_Exit\_OnlyWindow=1 "文件浏览器和窗口管理器 -- 插件: WinManager let g:winManagerWindowLayout='FileExplorer|TagList' nmap wm :WMToggle<cr> " tags "set tags=./tags "是否使用 quickfix 窗口来显示 cscope 结果 set cscopequickfix=s-,c-,d-,i-,t-,e- "映射cscope键盘 nmap <C-\_>s :cs find s <C-R>=expand("<cword>")<CR><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> nmap <C-\_>t :cs find t <C-R>=expand("<cword>")<CR><CR> nmap <C-\_>e :cs find e <C-R>=expand("<cword>")<CR><CR> nmap <C-\_>f :cs find f <C-R>=expand("<cfile>")<CR><CR> nmap <C-\_>i :cs find i <C-R>=expand("<cfile>")<CR><CR> nmap <C-\_>d :cs find d <C-R>=expand("<cword>")<CR><CR> "快速浏览和操作Buffer -- 插件: MiniBufExplorer "以下的两个功能需要在~/.vimrc中增加: let g:miniBufExplMapCTabSwitchBufs = 1"<C-Tab> 向前循环切换到每个buffer上,并在但前窗口打开 "<C-S-Tab> 向后循环切换到每个buffer上,并在但前窗口打开 "如果在~/.vimrc中设置了下面这句: let g:miniBufExplMapWindowNavVim = 1"则可以用<C-h,j,k,l>切换到上下左右的窗口中去,就像: "C-w,h j k l 向"左,下,上,右"切换窗口. "在~/.vimrc中设置: let g:miniBufExplMapWindowNavArrows = 1"是用<C-箭头键>切换到上下左右窗口中去 "c/h文件间相互切换 -- 插件: A nnoremap <silent> <F12> :A<CR>"意思是按F12时在一个新的buffer中打开c\\h文件, "在工程中查找 -- 插件: Grep nnoremap <silent> <F3> :Grep<CR>"在想查的词上按F3 "c智能补全 filetype plugin indent on"打开文件类型检测, 加了这句才可以用智能补全 set completeopt=longest,menu"关掉智能补全时的预览窗口 "加速你的补全 -- 插件: SuperTab let g:SuperTabRetainCompletionType=2"设置按下<Tab>后默认的补全方式 let g:SuperTabDefaultCompletionType="<C-X><C-O>"" 2 - 记住上次的补全方式,直到按ESC退出插入模式为止 "关闭了VI兼容模式,并允许进行文件类型检测 插件 OmniCppComplete: "c++补全ctag命令 ctags -R --c++-kinds=+p --fields=+iaS --extra=+q src set nocp filetype plugin on """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 更炫的语法高亮: 你可能会发现很多东西没有高亮起来, 比如运算符号, 各种括号, 函数名, 自定义类型等, 但是看上面的图片, 我的运算符号和函数名都加亮了^\_^, 想知道为什么吗? 哇哈哈哈哈.... 让我来教你吧 ... 主 要的思路是新建一个语法文件, 在文件中定义你要高亮的东东, 想高亮什么就高亮什么, 用vim就是这么自信. 所谓的语法文件就是vim用来高亮各种源文件的一个脚本, vim靠这个脚本的描述来使文件中的不同文本显示不同的颜色, 比如C语言的语法文件放在类似于这样的一个路径中: /usr/share/vim/vim64/syntax/c.vim 其他语言的语法文件也可以在这个路径中找到, 你的也许不在这个路径中, 不管它, 在你自己的HOME下新建一个语法文件, 新建一个空文件: ~/.vim/syntax/c.vim 在其中加入 <table style="width:461px;text-align:left;"> <tbody> <tr> <td style="vertical-align:top;"> <pre><br><br><br> <span style="color:rgb(255,255,255);">cFunction</span> <span style="color:rgb(255,255,255);">me=e-2</span><br> <span style="color:rgb(255,255,255);">cFunction</span> <span style="color:rgb(255,255,255);">me=e-1</span><br> <span style="color:rgb(255,255,255);">cFunction</span> <span style="color:rgb(255,255,255);">=</span> <span style="color:rgb(255,255,255);">=</span><br><br><br><br> <span style="color:rgb(255,255,255);">cMathOperator</span> <br><br> <span style="color:rgb(255,255,255);">cPointerOperator</span> <br><br> <span style="color:rgb(255,255,255);">cLogicalOperator</span> <br> <span style="color:rgb(255,255,255);"> cLogicalOperator</span> <br><br> <span style="color:rgb(255,255,255);">cBinaryOperator</span> <br> <span style="color:rgb(255,255,255);">cBinaryOperator</span> <br> <span style="color:rgb(255,255,255);">cBinaryOperatorError</span> <br><br> <span style="color:rgb(255,255,255);">cLogicalOperator</span> <br> <span style="color:rgb(255,255,255);"> cLogicalOperatorError</span> <br><br> <span style="color:rgb(255,255,255);">cMathOperator</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cPointerOperator</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cLogicalOperator</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cBinaryOperator</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cBinaryOperatorError</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cLogicalOperator</span> <span style="color:rgb(255,255,255);">=</span><br> <span style="color:rgb(255,255,255);">cLogicalOperatorError</span> <span style="color:rgb(255,255,255);">=</span><br></pre> </td> </tr> </tbody> </table> 再打开你的C文件看看, 是不是又明亮了许多. 还有一个压箱底的要告诉你, 如果你自己增加了一个类型或者结构之类的, 怎么让它也象"int", "void"这样高亮起来呢? 再在上面的文件~/.vim/syntax/c.vim中添加下面的东东: <table style="width:437px;text-align:left;"> <tbody> <tr> <td style="vertical-align:top;"> <pre><br><br><br> <span style="color:rgb(255,255,255);"> cType My_Type_1 My_Type_2 My_Type_3</span></pre> </td> </tr> </tbody> </table> 这样你自己的类型My\_Type\_1, My\_Type\_2, My\_Type\_3就也可以向"int"一样高亮起来了, 这样的缺点是每增加一个类型, 就要手动在这里添加一下 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 比较有用的几个命令 vnew 垂直开新装口 <C-W-W> 切换窗口 :helptags ~/.vim/doc 导入新文档 split 水平开新窗口 > touch新建一个文档两法 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ctags -R --c++-kinds=+p --fields=+iaS --extra=+q src(src是代码目录) 在对C++文件进行补全时,OmniCppComplete插件需要在标签文件中包含C++的额外信息,因此上面的ctags命令不同于以前我们所使用的,它专门为C++语言生成一些额外的信息,上述选项的含义如下: --c++-kinds=+p : 为C++文件增加函数原型的标签 \--fields=+iaS : 在标签文件中加入继承信息(i)、类成员的访问控制信息(a)、以及函数的指纹(S) \--extra=+q : 为标签增加类修饰符。注意,如果没有此选项,将不能对类成员补全 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 用到高亮的书签 -- 插件: VisualMark的时候总是报错 E197不能设置语言 en\_US之类的。 看help google好久 无解 最后进其插件源码看到有设置语言的一段注释“" Set the language to English” 连忙 $locale -a 把下面代码 exec ":lan mes en\_US"改为 exec ":lan mes en\_US.utf8"问题得以解决。 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 看来从win过来,要慢慢改变下习惯了,在linux下我们有看源码的机会,知所以然,这就是开源魅力之一?hh~ 现在是 winxp ubuntu双系统 ubuntu vbox了XPsp3 基本这样装后就回过1次win解决无法挂载问题。其他时候全在ubuntu里,实在要IE了要QQ要游戏的功能了就vbox。(ies4linux装了但是看flash那个闪的和天上的星星一样,没法阿^\_^~) 转载于:https://www.cnblogs.com/nniixl/archive/2008/05/21/1204413.html
还没有评论,来说两句吧...