---
title: "我的.vimrc配置"
author: "opencrazy"
date: "2009-04-08T22:19:01Z"
tags: []
slug: "vimrc"
draft: false
lastmod: "2009-04-08T22:19:01Z"
id: 363941
url: "https://opencrazy.iteye.com/blog/363941"
---

"Set mapleader
"let mapleader = ","
"let g:mapleader = ","
"
if &term=="xterm"
    set t_Co=8
    set t_Sb=^,*.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
""""""""""""""""""""""""""""""
   " Tag list (ctags)
""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag，只显示当前文件的
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口，则退出vim
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口 

				        
"使用<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'||&filetype == 'cpp'
exec "!g++ % -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: Zhengyou Zhou")
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
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType java set omnifunc=javacomplete#Complete