在终端下使用vim进行编辑时,默认情况下,编辑的界面上是没有显示行号、语法高亮度显示、智能缩进等功能的。为了更好的在vim下进行工作,需要手动设置一个配置文件:.vimrc。
在启动vim时,当前用户根目录下的.vimrc文件会被自动读取,该文件可以包含一些设置甚至脚本,所以,一般情况下把.vimrc文件创建在当前用户的根目录下比较方便。
安装了javacomplete和taglist两个插件,都可用在vim.sf.net上下载
"Set mapleader
let mapleader = ","
let g:mapleader = ","
"显示行号
set nu
"打开语法高亮
syntax on
set softtabstop=4
set shiftwidth=4
"关闭自动备份
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 plugin
filetype plugin on
filetype indent on
"设置配色方案为torte
colo torte
"设置支持的文件编码类项,目前设置为utf-8和gbk两种类型
set fileencodings=utf-8,chinese
"设置搜索结果高亮显示
"set hlsearch
"设置记录的历史操作列表
set history=50
"设置折叠
set foldcolumn=2
set foldmethod=indent
set foldlevel=3
"AutoCommand
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNew">File *.[ch],*.sh,*.java exec ":call SetTitle()"
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
"设置Java代码的自动补全
au FileType java setlocal omnifunc=javacomplete#Complete
"绑定自动补全的快捷键<C-X><C-O>到<leader>;
imap <leader>; <C-X><C-O>
"设定开关Taglist插件的快捷键为F4,可以在VIM的左侧栏列出函数列表等
map <F4> :Tlist<CR>
"设置程序的运行和调试的快捷键F5和Ctrl-F5
map <F5> :call CompileRun()<CR>
map <C-F5> :call Debug()<CR>
"设置tab操作的快捷键,绑定:tabnew到<leader>t,绑定:tabn, :tabp到<leader>n,
"<leader>p
map <leader>t :tabnew<CR>
map <leader>n :tabn<CR>
map <leader>p :tabp<CR>
"用cscope支持
set csprg=/usr/bin/cscope
let Tlist_Ctags_Cmd='/usr/bin/ctags'
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
"默认打开Taglist
"let Tlist_Auto_Open=1
"使用<leader>e打开当前文件同目录中的文件
if has("unix")
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
else
map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
endif
"定义CompileRun函数,用来调用进行编译和运行
func CompileRun()
exec "w"
"C程序
if &filetype == 'c'
exec "!gcc % -g -o %<"
exec "!./%<"
"Java程序
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
endif
endfunc
"结束定义CompileRun
"定义Debug函数,用来调试程序
func Debug()
exec "w"
"C程序
if &filetype == 'c'
exec "!gcc % -g -o %<"
exec "!gdb %<"
"Java程序
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
endif
endfunc
"结束定义Debug
"定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1, "\#########################################################################")
call append(line("."), "\# Author: Charlse.Zhang")
call append(line(".")+1, "\# Created Time: ".strftime("%c"))
call append(line(".")+2, "\# File Name: ".expand("%"))
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: Charlse.Zhang")
call append(line(".")+1, " Created Time: ".strftime("%c"))
call append(line(".")+2, " File Name: ".expand("%"))
call append(line(".")+3, " Description: ")
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
endfunc