""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""
"
"Support by yuance Li
"CopyRight @2010.7
"
""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""
" 把空格键映射成:
nmap :
" 快捷打开编辑vimrc文件的键盘绑定
map ee :e $HOME/.vimrc
autocmd! bufwritepost *.vimrc source $HOME/.vimrc
" 判断操作系统
if (has("win32") || has("win64") || has("win32unix"))
let g:isWin = 1
else
let g:isWin = 0
endif
" 判断是终端还是gvim
if has("gui_running")
let g:isGUI = 1
else
let g:isGUI = 0
endif
" tab转化为4个字符
set tabstop=4
set softtabstop=4
set shiftwidth=4
set nocompatible " 关闭兼容模式
syntax enable " 语法高亮
filetype plugin on " 文件类型插件
filetype indent on
set autoindent
autocmd BufEnter * :syntax sync fromstart
set nu " 显示行号
set cmdheight=2
set showcmd " 显示命令
set lz " 当运行宏时,在命令执行完成之前,不重绘屏幕
set hid " 可以在没有保存的情况下切换buffer
set backspace=eol,start,indent
set whichwrap+=<,>,h,l " 退格键和方向键可以换行
set incsearch " 增量式搜索
set hlsearch " 高亮搜索
set ignorecase " 搜索时忽略大小写
set magic " 额,自己:h magic吧,一行很难解释
set showmatch " 显示匹配的括号
set nobackup " 关闭备份
set wildmenu
set smartindent "根据上面的格式对其,智能选择对齐方式
"When you input a } or a {,vim will delete a TABSTOP
set cindent
" 不使用beep或flash
set vb t_vb=
set background=dark
colorscheme desert
"set t_Co=256
set history=400 " vim记住的历史操作的数量,默认的是20
set autoread " 当文件在外部被修改时,自动重新读取
set mouse=a " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等
"在gvim中高亮当前行
if (g:isGUI)
set cursorline
hi cursorline guibg=#333333
hi CursorColumn guibg=#333333
set guifont=Consolas\ 14
set guifontwide=Consolas\ 14
endif
" 设置字符集编码,默认使用utf8
if (g:isWin)
let &termencoding=&encoding " 通常win下的encoding为cp936
set fileencodings=utf8,cp936,ucs-bom,latin1
else
set encoding=utf8
set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1
endif
" 获取当前路径,将$HOME转化为~
function! CurDir()
let curdir = substitute(getcwd(), $HOME, "~", "g")
return curdir
endfunction
set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\
" 第80列往后加下划线
"au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)
" 用c-j,k在buffer之间切换
nn :bn
nn :bp
" 快捷输入
" 自动完成括号和引号
inoremap 1 ():let leavechar=")"i
inoremap 2 []:let leavechar="]"i
inoremap 3 {}:let leavechar="}"i
inoremap 4 {o}:let leavechar="}"O
inoremap q '':let leavechar="'"i
inoremap w "":let leavechar='"'i
" 缩写
iab idate =strftime("%Y-%m-%d")
iab itime =strftime("%H:%M")
iab imail stephenpcg@gmail.com
iab iname Li Yuance
"快捷键映射
"add save function
map :q
map :w!
imap :w!i
"插件设置
"set tablist and netrw
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap :WMToggle
"set new-omni-completion
"filetype plugin indent on "前面以设置
set completeopt=longest,menu
"匹配标签
imap
"根据头文件内关键字补全
imap
"补全文件名
imap
"根据当前文件里关键字补全
imap
"整行补全
imap
"根据字典补全
imap
"set miniBuf
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowNavArrows=1
"set grep
nnoremap :Grep
"set c/h change
nnoremap :A
"key mapping to stop search highlight
map :nohlsearch
" 更新ctags和cscope索引
" href: 把vim打造成一个真正的ide2.html
" 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令
map :call Do_CsTag()
function! Do_CsTag()
let dir = getcwd()
"先删除已有的tags和cscope文件,如果存在且无法删除,则报错。
if ( DeleteFile(dir, "tags") )
return
endif
if ( DeleteFile(dir, "cscope.files") )
return
endif
if ( DeleteFile(dir, "cscope.out") )
return
endif
if(executable('ctags'))
silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
endif
if(executable('cscope') && has("cscope") )
if(g:isWin)
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
else
silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files"
endif
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
" 刷新屏幕
execute "redr!"
endfunction
function! DeleteFile(dir, filename)
if filereadable(a:filename)
if (g:isWin)
let ret = delete(a:dir."\\".a:filename)
else
let ret = delete("./".a:filename)
endif
if (ret != 0)
echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None
return 1
else
return 0
endif
endif
return 0
endfunction
" cscope 绑定
set cscopequickfix=s-,c-,d-,i-,t-,e-,g-,f-
"查找本C符号
nmap :cs find s =expand("")
"查找本定义
nmap :cs find g =expand(""):cw
"调用本函数的函数
nmap :cs find c =expand(""):cw
"查找本字符串
nmap :cs find t =expand(""):cw
"egrep模式
nmap :cs find e =expand(""):cw
"查找本文件
nmap :cs find f =expand(""):cw
"查找包含本文件的文件
nmap :cs find i =expand(""):cw
"本函数调用的函数
nmap :cs find d =expand(""):cw
"添加注释
function AddTitle()
call setline(1,"#****************************************************")
call append(1,"# Author: Li Yuance - liyuance@gmail.com")
call append(2,"# " . "Last modified: " . strftime("%Y-%m-%d %H:%M"))
call append(3,"# Filename: " . expand("%"))
call append(4,"# Description: ")
call append(5,"#****************************************************")
endf
"set voof
map :Voof
"映射添加注释快捷键
map zg :call AddTitle():$o
"映射修改注释快捷键
map mg :/# *Last modified: /s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@
"全选ctrl+a
map ggvG
"设置gvim字体
set guifont=Monospace\ 14
set guifontwide=Monospace\ 14
"设置gvim不闪烁
set novisualbell
"设置#注释
vmap : s/^/#/
vmap ZZ :s/^##*//
阅读(1479) | 评论(0) | 转发(0) |