将Vim打造成一个便捷好用的IDE之路


1. ctaglist

用途:通过它,可以显示源码的整体架构,如函数列表等,方便地进行跳转。

安装步骤:

  • http://www.vim.org/scripts/script.php?script_id=273下载taglist
  • 将下载的安装包解压后的"plugin/taglist.vim"和"doc/taglist.txt"文件分别放在 "[Vim安装路径]\vimfiles"对应的plugin和doc文件夹下
  • 启动Vim,运行":helptags ."命令。此步骤是将doc下的"taglist.txt"帮助文档加入到Vim的帮助主题中,这样我们就可以通过在Vim中运行“help taglist.txt”查看taglist帮助。
  • 在_vimrc文件(相对于linux中的.vimrc文件)中添加以下命令,即将此工具添加到Vim的路径中:
    let Tlist_Show_One_File=1     "不同时显示多个文件的tag,只显示当前文件的  
    let Tlist_Exit_OnlyWindow=1   "如果taglist窗口是最后一个窗口,则退出vim 
    let Tlist_Ctags_Cmd="/usr/bin/ctags" "将taglist与ctags关联

  • 重启Vim
  • 你可以运行":Tlist"或":TlistToggle"命令来打开或关闭taglist窗口,查看taglist帮助时运行":help taglist"命令。
 一个简单的方法是设定快捷键,在.vimrc中增加一行:
nnoremap <silent> <F8> :TlistToggle<CR>

这样在vim中按F8就可以打开/关闭taglist了。

其他设置参见taglist帮助,即运行":help taglist.txt"。


我的_vimrc文件设置:

最后,下面是我的_vimrc中使用的设定,希望能够抛砖引玉:

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

"========================================
"下面都是自定义的内容
"========================================

"使用中文帮助文档
set helplang=cn

"Set mapleader
let mapleader = ","
let g:mapleader = "," 

"显示行号
set nu

"打开语法高亮
syntax on

"用4个空格代替TAB符. 只在编辑c, cpp时实行这种设置
autocmd FileType c,cpp set shiftwidth=4 | set expandtab

"关闭自动备份
set nobackup 

"自动缩进设置
set cindent
set smartindent
set incsearch
set autoindent

"Show matching bracets
set showmatch

"Get out of VI's compatible mode
set nocompatible

"Have the mouse enabled all the time
set mouse=a

"Set to auto read when a file is changed from the outside
set autoread

"Enable filetype detection, plugin, and indent on
filetype plugin indent on

"设置折叠
set foldcolumn=2
set foldmethod=indent
set foldlevel=3 


"AutoCommand
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.[ch],*.sh,*.java exec ":call SetTitle()"
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G 


"定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1, "/#########################################################################")
call append(line("."), "/# Author: OAK")
call append(line(".")+1, "/# Created Time: ".strftime("%c"))
call append(line(".")+2, "/# File Name: ".expand("%:t"))
call append(line(".")+3, "/# Description: ")
call append(line(".")+4, "/#########################################################################")
call append(line(".")+5, "/#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " Author: OAK")
call append(line(".")+1, " Created Time: ".strftime("%c"))
call append(line(".")+2, " File Name: ".expand("%:t"))
call append(line(".")+3, " Description: ")
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
endfunc


"定义CompileRun函数,用来调用进行编译和运行
func CompileRun()
exec "w"
"C程序
if &filetype == 'c'
exec "!gcc -Wall % -g -o %<.exe"
"c++程序
elseif &filetype == 'cpp'
exec "!g++ -Wall % -g -o %<.exe"
"Java程序
elseif &filetype == 'java'
exec "!javac %"
endif
endfunc
"结束定义CompileRun
"定义Run函数
func Run()
if &filetype == 'c' || &filetype == 'cpp'
exec "!%<.exe"
elseif &filetype == 'java'
exec "!java %<"
endif
endfunc
"定义Debug函数,用来调试程序
func Debug()
exec "w"
"C程序
if &filetype == 'c'
exec "!gcc % -g -o %<.exe"
exec "!gdb %<.exe"
elseif &filetype == 'cpp'
exec "!g++ % -g -o %<.exe"
exec "!gdb %<.exe"
"Java程序
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
endif
endfunc
"结束定义Debug
"设置程序的运行和调试的快捷键F5和Ctrl-F5
map <F5> :call CompileRun()<CR>
map <F6> :call Run()<CR>
map <C-F5> :call Debug()<CR>

"设置文件的代码形式
set encoding=utf-8
set termencoding=cp936 "解决gvim不乱码但vim乱码的问题
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese

"vim的菜单乱码解决:
"同样在 _vimrc文件里以上的中文设置后加上下列命令,
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

"vim的提示信息乱码解决
language messages zh_CN.utf-8

vi/vim使用进阶: 目录

http://easwy.com/blog/archives/advanced-vim-skills-catalog/


【参考文档】

  • http://blog.csdn.net/duguteng/article/details/7414592
  • http://blog.csdn.net/williamchang/article/details/1806033
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值