Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1692009
  • 博文数量: 177
  • 博客积分: 9416
  • 博客等级: 中将
  • 技术积分: 2513
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-06 16:08
文章分类

全部博文(177)

文章存档

2013年(4)

2012年(13)

2011年(9)

2010年(71)

2009年(12)

2008年(11)

2007年(32)

2006年(25)

分类: C/C++

2007-06-15 14:59:18

看了gis76748853的帖子,想起来vim的拥趸也不少,因此在这里献个丑,简单讲解一下配置vim/gim作为程序开发的集成环境。
 
一般而言,Linux的发行版都会提供选择是否安装vim编辑器。如果你没有选上,没关系,可以从发行版光盘里找到相应的rpm包进行安装,也可以使用源代码安装。本文推荐源代码安装,因为不需要root权限。而在windows平台有相应的exe安装文件。不推荐使用windows作为日常工作的操作系统。如果你是linuxer/unixer,相信你不会使用windows的:)
 
首先,到vim的官方网站下载最新版本的源码包(当然要stable的)。一般以tar.bz2包形式提供。
 
以下以vim 7.0作为示例(其中的大写单词为变量,请根据实际情况替换):
1、安装
$ tar xfj vim-7.0.tar.bz2
$ cd vim70
如果你在字符终端下使用vim,则使用如下命令:
$ mkdir $SHARE_INSTDIR
$ mkdir $BIN_INSTDIR
$ ./configure --disable-gui --without-x --prefix=$SHARE_INSTDIR --exec-prefix=$BIN_INSTDIR
否则:
$ ./configure --prefix=$SHARE_INSTDIR --exec-prefix=$BIN_INSTDIR
 
然后,编译并安装:
$ make && make install
 
2、安装插件(可以到下载):
基本插件:
bufexplorer,winmanager,vimtips
$ mkdir ~/.vim
$ for plgin in bufexplorer.zip winmanager.zip vimtips.zip
  do
      unzip $plgin
  done
 
C/C++,CVS,cscope,ctags等用于C/C++开发的插件:
autoload_cscope.vim, c.vim, code_complete.vim, crefvim.zip, cscopemenu.vim, cvsmenu.vim。
其中,以vim作为后缀的文件直接考到~/.vim/plugin目录,其余的在~/.vim目录下解压缩。每个插件都会有简要的使用说明。just read it。
 
3、配置
在你的profile或者bashrc或者cshrc等启动脚本里面加上:
export PATH=$BIN_INSTDIR:$PATH
然后进行vimrc的配置。修改~/.vimrc文件,使用如下内容:
set nobackup            " do not keep a backup file, use versions instead
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set number
set incsearch           " do incremental searching
set hlsearch
set fileformat=unix
set textwidth=78
set formatoptions+=mM
set autoindent          " always set autoindenting on
set splitbelow
botright cwindow
" Don't use Ex mode, use Q for formatting
map Q gq
syntax on
filetype on
if has("gui_running")
    let do_syntax_sel_menu=1
    map :cn
    map :cp
endif

if has("autocmd")
  augroup vimrcEx
  au!
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif
  augroup END
else

endif " has("autocmd")
set smartindent
set wrap
set makeprg=make
set guifont=Courier\ 10\ Pitch
set tabstop=4
set shiftwidth=4
set expandtab
au BufNewFile,BufRead *.cv
    \ if exists("c_syntax_for_h") | setf c |
    \ else | setf cpp | endif
au BufNewFile,BufRead *.pc
    \ if exists("c_syntax_for_h") | setf c |
    \ else | setf cpp | endif
set shortmess=a
if !has("gui_running")
        set t_Co=8
        set t_Sf=1%dm
        set t_Sb=1%dm
    set wildmenu
endif
" Use mouse on console
if has("wildmenu")
    set mouse =a
endif
" Set text-mode menu
if has("wildmenu")
    " Use menu
        source $VIMRUNTIME/menu.vim
    set cpoptions-=<
    set wildcharm=
    map :emenu
endif
if has("cscope")
        set csprg=/usr/bin/cscope
        set csto=0
        set cst
        set nocsverb
        " add any database in current directory
        if filereadable("cscope.out")
            cs add cscope.out
        " else add database pointed to by environment
        elseif $CSCOPE_DB != ""
            cs add $CSCOPE_DB
        endif
        set csverb
endif
nnoremap :exe ":!info ".expand("")
" Window manager settings
map :WMToggle
map :FirstExplorerWindow
map :BottomExplorerWindow
let persistentBehaviour=0
let winManagerWidth=25
" Tag list settings
map :Tlist
let Tlist_Exit_OnlyWindow = 1
let Tlist_Auto_Open = 1
let Tlist_Auto_Update = 1
let Tlist_WinWidth = 25
let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=1
if $VIM_HATE_SPACE_ERRORS != '0'
    let c_space_errors=1
endif
这样,一个功能强大的开发环境就配置好了。
 
4、使用
a) 在对源码进行修改或者添加新的源码文件之后请及时使用cscope和ctags命令更新tags和cscope.out文件并重新装载。
b) 在字符终端上,使用F4键调出菜单。
c) 使用Ctrl+p来完成一个单词。
d) 使用(来完成函数的参数列表,并用tab键在参数表中切换。
e) 使用\cr来查找关键字
f) 使用F2来打开文件列表
g) 使用F3来打开tags列表
在图形界面下(gvim)
h) 使用F11切换到上一个缓冲
i) 使用F12切换到下一个缓冲
 
PS:最初我使用source insight,后来公司不允许使用盗版,又没有买source insight,因此我就开始使用vim。经过一段时间探索,我认为,加上各种插件的vim功能要远远强于source insight!
 
Happy VIMing!
 
Copyleft (C) 2007-2009 raof01.
本文可以用于除商业外的所有用途。此处“用途”包括(但不限于)拷贝/翻译(部分或全部),不包括根据本文描述来产生代码及思想。若用于非商业,请保留此 权利声明,并标明文章原始地址和作者信息;若要用于商业,请与作者联系(raof01@gmail.com),否则作者将使用法律来保证权利。
阅读(3211) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~