-
2009-09-10
程序员常用软件清单-VIM篇 - [软件清单]
khb.hnu@gmail.com
1 VIM及插件
VIM应该是我近两年时间里用得最多的软件之一吧,从研一开学还不知道Linux,ubuntu是些什么东西,到现在彻底喜欢上Linux系统刚好 2年的时间.Linux让我着迷很大一部分原因是从VIM开始的.我现在应该可以完全脱离Windows系统工作.
由于VIM的强大,所有这里特别把这款工具作为一个篇来讲述.
维基百科:
VIM is a text editor first released by Bram Moolenaar in 1991 for the Amiga computer. The name "VIM" is an acronym for "Vi IMproved" because VIM was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code. VIM is cross-platform. It is the most popular editor amongst Linux Journal readers.Released under a software license compatible with the GNU General Public License,VIM is free and open source software. The program's license includes some charityware clauses, encouraging users who enjoy the software to consider donating to children in Uganda.官方网站地址:www.vim.org.
哈哈,突然发现,VIM跟Linux是同一年诞生的.
关于VIM的一些具体使用我不列出来,组合命令实在太多罗.需要通过反复的练习才能牢记在心.如果想系统的学习VIM,建议 看一下VIM的手册,网上有中文翻译版.作为程序员,尤其需要看第29章(之于程序),第30章(程序的编辑).同时第3章(移动),第4章(小幅改动), 第10章(大刀阔斧)这几章中的内容用得比较多.
下面我列举几点学习VIM的注意事项:
- VIM的入门比较难,要坚持住.一旦熟练使用,效率蹭蹭地往上升.
- 要明确区分插入模式,命令模式,普通模式,选择模式.
- 在学习开始阶段要强迫自己使用键盘,而不是鼠标.
- 要用VIM的思维去操作,例如 上下左右移动分别使用j,k,h,l,而不是键盘上的方向键.
- 学习下正则表达式吧,在替换等操作时会带来好处的.
- 不要一次把所有的命令记下来,一次记几个,然后反复使用,孰能生巧.
- 多到网上跟别人交流,特别可以参考写别人写得比较好的.vimrc或者_vimrc文件配置.
- 想要深入学习,尝试自己开发出一个实用的插件吧.
这篇文章主要是列举一些我平时用得比较多的VIM插件.
1.1 C-Support
- C-Support:Write and run programs. Insert statements, idioms, comments etc.
它具有如下功能:
- Statement oriented editing of C/C++ programs
- Speed up writing new code considerably
- Write code and comments with a professional appearance from the beginning
- Use code snippets
教程(google能搜索到):Make VIM as Your C/C++ IDE Using c.vim Plugin
之所以第一个介绍这个插件,是因为它确实能够为我编写程序节省不少时间,还能减少程序的bug.同时我很喜欢它里面默认的一个makefile模板,真的 很通用,只要把自己所需要的额外的头文件路径,库路径,以及源程序文件名相应的填写进去,就可以使用.源程序的依赖关系是通过sed工具处理自动完成. 使用VIM进行C/C++编程,这个插件绝对会让你满意!
注:在VIM下需要记住一些常用的命令,如果是在GVIM下,可以点击菜单选项进行操作.
1.2 Bash-Support
- Bash-Support:Write and run BASH-scripts using menus and hotkeys
这个跟第一个基本类似,只是针对的语言是bash,而非c/c++;这里不再详细介绍,这相关的插件还有perl-support;
两个相关教程如下:
Make VIM as Your Perl IDE Using bash-support.vim Plugin
Make VIM as Your Perl IDE Using perl-support.vim Plugin注:http://www.thegeekstuff.com/tag/vi-vim-tips-and-tricks中有大量关于VIM以及VIM插件使用教程,上面列出来的3篇教程 都来自该网站.
1.3 Ctags与Taglist
- Taglist:Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)
taglist必须要与ctags配合才能使用.taglist需要利用ctags生成的tags文件.在Windows下使用IDE的用户都可能会知道 Visual.Assist插件可以列出当前源程序中的函数名,全局变量,结构体定义等等.taglist实现的就是这个功能.如果再配合 winmanager这个文件管理插件使用,那基本就可以把VIM打造成一个IDE开发环境.
关于这个插件的教程网上一堆堆的,需要的自己google下吧.
taglist这个插件我开始使用VIM的时候用得比较多,后来对VIM有进一步了解后,一般通过命令进行跳转,而不调出个新的窗口. 不过ctags这个插件我是少不了,"CTRL+] CTRL+T" 这对组合不知道用过多少次,太爽啦.跳转就在一瞬间.
1.4 Code-Complete
- Code-Complete:Function parameter complete,Code snippets,and much more.
看插件名称就知道这个插件的功能是什么吧,没错,就是代码补全.
这个插件使用比较简单.下面贴出官方网站的说明:
In insert mode, when you type "<tab>"(default value of g:completekey) after function name with a "(",function parameters will be append behind, use "<tab>" key again to switch between parameters. This key is also used to complete code snippets. Example: press <tab> after function name and ( foo ( <tab> becomes: foo ( `<first param>`,`<second param>` ) press <tab> after code template if <tab> becomes: if( `<...>` ) { `<...>` } NOTE:Use the command below to create tags file including signature field. ctags -R --c-kinds=+p --fields=+S .1.5 A
- A:Alternate Files quickly (.c - .h etc)
头文件与源文件之间的快速切换,简单,实用,over!
1.6 QuickFix
摘自VIM英文手册:
VIM has a special mode to speedup the edit-compile-edit cycle. This is inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga. The idea is to save the error messages from the compiler in a file and use VIM to jump to the errors one by one. You can examine each problem and fix it, without having to remember all the error messages. VIM has a special mode to speedup the edit-compile-edit cycle. This is inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga. The idea is to save the error messages from the compiler in a file and use VIM to jump to the errors one by one. You can examine each problem and fix it, without having to remember all the error messages.QuixkFix已经做到VIM 7.0的标准中.在编译源程序出错的时候会弹出这个窗口.在下面要介绍的grep插件中也会用到这个窗口. 而且还有一个好处,通过命令可以跳转到相应的文件相应的行上.我默认配置F5跳转到上一个错误/匹配成功出现的位置,F6为跳转 到下一个错误/匹配成功出现的位置.
1.7 Grep
- Grep:Grep search tools integration with VIM
将grep工具的功能内置到VIM中去,真的很实用.将光标至于某个单词上,按配置好的快捷键,就可以搜索当前文件,或者当前目录下出现 该单词的每一行信息.匹配成功的项目会显示在QuickFix窗口中.然后通过命令(或者配置快捷键)进行跳转.
1.8 New-omni-completion
摘自VIM英文手册:
This could also be called intellisense", but that is a trademark. It is a smart kind of completion. The text in front of the cursor is inspected to figure out what could be following. This may suggest struct and class members, system functions, etc.相信在windows下编程的程序员一定会用过自动补全功能,但输入"->" "."后,类成员函数或变量,结构体成员变量会自动弹出来,然后就可以 选择确认,比每次手动输入要快,还能避免错误,VIM的这个插件也具有这个功能.并且这个插件已经称为VIM 7中默认就会安装的标准插件.
用法:进入Insert模式, 将光标放在"->"后面,然后按下"Ctrl+X Ctrl+O", 此时会弹出一个下列菜单, 显示所有匹配的标签.其他的高级用法 查看VIM手册.
注:该插件需要配合tags(有ctags生成)才能使用.
随机文章:
Vim tips 2008-06-13程序员常用软件清单-编程篇 2009-09-08vim+google code search 2009-08-19linux下各种文本文件转pdf 2009-08-15
Post Addr: