vi 利器

1. 结合ctag

   1.1、 建立索引

               cd到预建立索引的目录,然后在终端使用命令如下   # ctag -R *,就可以建立索引了

   1.2、 用vi进行搜索

                在终端使用命令 #vi -t main     --这个的意思就是:查找所有的文件有出现main的函数或变量的地方

   1.3、 在vi的命令格式下,使用 tp--返回到前一个搜索到的位置,tn返回到后一个搜索到的位置

   1.4、 当有多个搜索到的值的时候,在vi命令行的状态下,使用 ts列出所有的搜索到的列表

   1.5、  注意点,vi运行的目录与tags所在的目录是一致的

2. 结合Taglist 

   1。 Taglist 需要自己下载,下载安装的时候注意要解压到 root's home 下面的 .vim目录下,建议你要显示隐藏的文件。否则容易一头雾水。

  2。  解压完成后,修改vimrc这个文件,这个文件有可能是存放在etc/下,新增的内容 ("表示注释)

""""""""for ctags"""""""""""""" 

set tags=tags;

""""""""""""""""""""""""""""""

let Tlist_Show_One_File = 1 

let Tlist_Use_Right_Window = 1 

let Tlist_Exit_OnlyWindow = 1

   3.转到你要操作的源码目录下,然后用 vim main.cpp 这样打开一个文件(!!!注意不是 vi main.cpp,否则命令不能识别)

      vim下 taglist 几个简单的命令 :

              打开taglist窗口   TlistToggle、TlistOpen 打开taglist窗口,再一次输入 TlistToggle或输入 TlistClose则关闭窗口。

              在tagList窗口下, ctrl+w可以切换 vim操作窗口和taglist操作窗口, 光标指向某一个function或变量,然后 o 则打开新窗口移动到定义处,p定位到function所在的源文件。+展开tag,-收缩tag,向上的箭头或者ctrl+w在各个窗口进行切换 

   4。OmniCppComplete 自动补全

       4.1 下载zip包

        4.2 解压到 .vim目录下

        4.3  查看它的帮助文档

        4.4  根据帮助文档 修改vimrc 的配置和配置自己的操作习惯

下表是我的vimrc中设置的键绑定,使用pumvisible()来判断下拉菜单是否显示,如果下拉菜单显示了,键映射为了一个值,如果未显示,又会映射为另一个值。

" mapping
inoremap <expr> <CR>       pumvisible()?"\<C-Y>":"\<CR>"
inoremap <expr> <C-J>      pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"
inoremap <expr> <C-K>      pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"
inoremap <expr> <C-U>      pumvisible()?"\<C-E>":"\<C-U>" 

上面的映射都是在插入模式下的映射,解释如下:

  • 如果下拉菜单弹出,回车映射为接受当前所选项目,否则,仍映射为回车;
  • 如果下拉菜单弹出,CTRL-J映射为在下拉菜单中向下翻页。否则映射为CTRL-X CTRL-O
  • 如果下拉菜单弹出,CTRL-K映射为在下拉菜单中向上翻页,否则仍映射为CTRL-K
  • 如果下拉菜单弹出,CTRL-U映射为CTRL-E,即停止补全,否则,仍映射为CTRL-U

c.vim的功能就不介绍了,直接来这里可以看到并且提供下载地址。

安装方法也很简单,

直接解压到~/.vim/(for linux)或者/vimfiles/(for win),并且plugin on一下就可以了,

具体可以看插件附带的readme.

这里提供使用方法,我做一下简单的总结。

----------华丽分割------------

1.在~/.vim/c-support/templates/templates可以设置版权信息,如作者、信箱、版权归属等,新建.c或.cpp文件是可以看到,并且列出了使用模板文件位置,可以自己编辑

2.\if    插入一般函数

3.\im    插入主函数

4.\cfu    插入函数头,即函数说明

5.\cfr    插入一个frame comment,可以用来写变量说明

6.\p<    插入一个include , 并且把光标放在<>中

7.\rc    保存并编译

8.\rr   运行

9.\nr    可以在~/.vim/c-support/codesnippets中编写一些预编译代码或者代码块,通过此命令使用

---------------------------------------------

总之c.vim是个不错的c/c++辅助代码插件 , 恩.

---------------------附:具体的c.vim hotkey-------------------------

-- help ---------------------------------------------------------------

\hm show manual for word under the cursor (n,i)
\hp show plugin help (n,i)

-- comments -----------------------------------------------------------

\cl end-of-line comment (n,v,i)
\cj adjust end-of-line comment(s) (n,v,i)
\cs set end-of-line comment column (n)
\c* code -> comment /* */ (n,v)
\cc code -> comment // (n,v)
\co comment -> code (n,v)
\cfr frame comment (n,i)
\cfu function comment (n,i)
\cme method description (n,i)
\ccl class description (n,i)
\cd date (n,v,i)
\ct date \& time (n,v,i)

-- statements ---------------------------------------------------------

\sd do { } while (n,v,i)
\sf for (n,i)
\sfo for { } (n,v,i)
\si if (n,i)
\sif if { } (n,v,i)
\sie if else (n,v,i)
\sife if { } else { } (n,v,i)
\sw while (n,i)
\swh while { } (n,v,i)
\ss switch (n,v,i)
\sc case (n,i)
\s{ { } (n,v,i)

-- preprocessor -------------------------------------------------------

\p< #include <> (n,i)
\p" #include "" (n,i)
\pd #define (n,i)
\pu #undef (n,i)
\pie #if #else #endif (n,v,i)
\pid #ifdef #else #endif (n,v,i)
\pin #ifndef #else #endif (n,v,i)
\pind #ifndef #def #endif (n,v,i)
\pi0 #if 0 #endif (n,v,i)
\pr0 remove #if 0 #endif (n,i)
\pe #error (n,i)
\pl #line (n,i)
\pp #pragma (n,i)

-- idioms -------------------------------------------------------------

\if function (n,v,i)
\isf static function (n,v,i)
\im main() (n,v,i)
\i0 for( x=0; x<n; x+=1 ) (n,v,i)
\in for( x=n-1; x>=0; x-=1 ) (n,v,i)
\ie enum + typedef (n,i)
\is struct + typedef (n,i)
\iu union + typedef (n,i)
\ip printf() (n,i)
\isc scanf() (n,i)
\ica p=calloc() (n,i)
\ima p=malloc() (n,i)
\isi sizeof() (n,v,i)
\ias assert() (n,v)
\ii open input file (n,i)
\io open output file (n,i)

-- snippets -----------------------------------------------------------

\nr read code snippet (n,i)
\nw write code snippet (n,v,i)
\ne edit code snippet (n,i)
\np pick up prototype (n,v,i)
\ni insert prototype(s) (n,i)
\nc clear prototype(s) (n,i)
\ns show prototype(s) (n,i)
\ntl edit local templates (n,i)
\ntg edit global templates (n,i)
\ntr rebuild templates (n,i)

-- c++ ----------------------------------------------------------------

\+co cout << << endl; (n,i)
\+c class (n,i)
\+cn class (using new) (n,i)
\+ci class implementation (n,i)
\+cni class (using new) implementation (n,i)
\+mi method implementation (n,i)
\+ai accessor implementation (n,i)

\+tc template class (n,i)
\+tcn template class (using new) (n,i)
\+tci template class implementation (n,i)
\+tcni template class (using new) impl. (n,i)
\+tmi template method implementation (n,i)
\+tai template accessor implementation (n,i)

\+tf template function (n,i)
\+ec error class (n,i)
\+tr try ... catch (n,v,i)
\+ca catch (n,v,i)
\+c. catch(...) (n,v,i)

-- run ----------------------------------------------------------------

\rc save and compile (n,i)
\rl link (n,i)
\rr run (n,i)
\ra set comand line arguments (n,i)
\rm run make (n,i)
\rg cmd. line arg. for make (n,i)
\rp run splint (n,i)
\ri cmd. line arg. for splint (n,i)
\rk run codecheck (tm) (n,i)
\re cmd. line arg. for codecheck (tm) (n,i)
\rd run indent (n,v,i)
\rh hardcopy buffer (n,v,i)
\rs show plugin settings (n,i)
\rx set xterm size (n, only linux/unix & gui)
\ro change output destination (n,i)


注:
下载地址:http://www.vim.org/scripts/script.php?script_id=213

package
script version
date
vim version
user
release notes

cvim.zip
5.5
2009-02-17
7.0
fritz mehner
+ additional plugin-tags (jump targets in templates): <+text+>, <-text->. 
+ additional mapping ctrl-j : jump to these new targets. 
+ template-file: additional macro |style| and if-endif-construct to easily 
  choose between sets of templates. 
+ additional mapping: auto-complete classical c comment (also multi-line). 
+ additional mapping: auto-complete open block starting with {<cr> . 
+ visual mode for date and time insertion (menu 'comments'). 
+ visual mode for tags (submenu 'comments->tags (plugin)'). 
+ bugfix: hotkey \ica not working 

+ bugfix: hotkey shift-f2 for the alternate-plugin disappeared.

!!!!!!!!!!!!!!!!!!              \if   在什么时候输入? 在命令模式下没有出现 ":" 的时候输入,这个是大部分初学者遇到的问题 

原文地址:https://www.cnblogs.com/xianqingzh/p/1727401.html