一步步将vim改造成C/C++开发环境(IDE)
操作系统:Ubuntu Desktop 10.04 LTS

转载请注明出处lingdxuyan.blog.chinaunix
一步步将vim改造成C/C++开发环境(IDE)
原文地址blog168.chinaunix/space.php?uid=23089249&do=blog&id=2855999

【参考资料】
吴垠的“手把手教你把Vim改装成一个IDE编程环境”
在Fedora下成功将Vim打造成适用于C/C++的IDE
用Vim搭建C/C++开发环境
Ubuntu下vim+ctags的配置(转)
Vim下的代码自动补全和代码跳转阅读(转)
omnicppcomplete - a Vim plugin
我的vim IDE界面:
1、安装VimVim基本插件
首先安装好VimVim的基本插件。这些使用apt-get安装即可:
lingd@ubuntu:~/arm$sudoapt-get install vim vim-scripts vim-doc
其中vim-scriptsvim的一些基本插件,包括语法高亮的支持、缩进等等。
vim中文帮助文档tar包下载地址:
sourceforge/projects/vimcdoc/files/vimcdoc/
解压后其中有个doc文件夹, 将其中的内容全部复制到~/.vim/doc, 或者vim安装目录下的doc目录中, 此时vim中的help信息已经是中文的了.
网页版中文帮助文档网址vimcdoc.sourceforge/doc/help.html
首页就时vim帮助文档的目录,阅读起来更方便有效、更有针对性!
2Vim配置文件
Vim强大的功能,其来源基本上就两个地方:Vim插件以及Vim配置文件。
Vim本身的系统配置文件夹是在/usr/share/vim//etc/vim/两个文件夹下。一般情况下,我们
不会去改变这两个文件夹下的配置文件,而是在用户文件夹/home/user(其中,user为用户名,我的用户名是lingd)下建立自己的配置文件。进入用户文件夹(/home/user/)之后,用gedit新建一个名叫.vimrc的文件:
lingd@ubuntu:~/arm$cd ~
lingd@ubuntu:~$gedit .vimrc
注:使用gedit主要是为了方便大段大段的文字粘贴!
然后把下面的文字拷贝进这个文件之后保存:
1 " This line should not be removed as it ensures that various options are
2 " properly set to work with the Vim-related packages available in Debian.
3 debian.vim
4
5 " Uncomment the next line to make Vim more Vi-compatible
6 " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
7 " options, so any other options should be set AFTER setting 'compatible'.
8 set nocompatible
9
10 " Vim5 and later versions support syntax highlighting. Uncommenting the
11 " following enables syntax highlighting by default.
12 if has("syntax")
13 syntax on " 语法高亮
14 endif
15 colorscheme ron " elflord ron peachpuff default 设置配方案,vim自带的配方案保存在/usr/share/vim/vim72/colors目录下
16
17 " detect file type
18 filetype on
19 filetype plugin on
20
21 " If using a dark background within the editing area and syntax highlighting
22 " turn on this option as well
23 setbackground=dark
24
25 " Uncomment the following to have Vim jump to the last position when
26 " reopening a file
27 ifhas("autocmd")
28 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
29 "have Vim load indentation rules and plugins according to the detected filetype
30 filetype plugin indent on
31 endif
32
33 " The following are commented out as they cause vim to behave a lot
34 " differently from regular Vi. They are highly recommended though.
35
36 "set ignorecase "搜索模式里忽略大小写
37 "set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
38 setautowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next:rewind:last:first:previous:stop:suspend:tag:!:makeCTRL-] CTRL-^命令时进行;用 :bufferCTRL-OCTRL-I'{A-Z0-9} `{A-Z0-9} 命令转到别的文件时亦然。
39 set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
40 "set smartindent "智能对齐方式
41 settabstop=4 " 设置制表符(tab)的宽度
42 set softtabstop=4 " 设置软制表符的宽度
43 setshiftwidth=4 " (自动) 缩进使用的4个空格
44 set cindent " 使用 C/C++ 语言的自动缩进方式
45 setcinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
46 "set backspace=2 " 设置退格键可用
47 set showmatch " 设置匹配模式,显示匹配的括号
48 setlinebreak " 整词换行
49 set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
50 "set hidden "Hide buffers when they are abandoned
51 setmouse=a " Enable mouse usage (all modes) "使用鼠标
52 setnumber " Enable line number "显示行号
53 "set previewwindow "标识预览窗口
54 sethistory=50 " set command history to 50 "历史记录50
55
56
57 "--状态行设置--
58 set laststatus=2 " 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行
59 setprintf函数的用法pythonruler " 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。
60
61 "--命令行设置--
62 setshowcmd " 命令行显示输入的命令
63 set showmode " 命令行显示vim当前模式
64
65 "--find setting--
66 set incsearch " 输入字符串就显示匹配点
67 sethlsearch
注:配置文件中,以单个双引号开头的文字为注释。
保存文件之后,启动Vim。此时,Vim已经是这种效果了(语法高亮挺漂亮的这个是由vim-scripts中的插件支持的):

3ctags安装与配置
ctags可以建立源码树的标签索引(标签就是一个标识符被定义的地方,如函数定义),使程序员在编程时能迅速定位函数、变量、宏定义等位置去查看原形
以下是在ubuntuctags的下载安装和配置过程:
下载并安装ctags,终端输入命令
lingd@ubuntu:~/arm$sudo apt-get install ctags
建立源码索引,比如我经常需要查阅Linux的内核代码,而这些代码放在/home/lingd/arm/linux-2.6.24.7目录下
那么在终端进入到该目录后,输入命令ctags -R *,你会发现多了一个tags文件,这个就是索引文件
lingd@ubuntu:~/arm$cd linux-2.6.24.7
lingd@ubuntu:~/arm/linux-2.6.24.7$ls
arch crypto include kernel mm samples usr
block Documentation init lib net scripts
COPYING drivers ipc MAINTAINERS README security
CREDITS fs Kbuild Makefile REPORTING-BUGS sound
lingd@ubuntu:~/arm/linux-2.6.24.7$ctags -R *
lingd@ubuntu:~/arm/linux-2.6.24.7$ls
arch crypto include kernel mm samples tags
block Documentation init lib net scripts usr
COPYING drivers ipc MAINTAINERS README security
CREDITS fs Kbuild Makefile REPORTING-BUGS sound