set nocompatible
set magic
"Display related
set ru "标尺信息
set sm
set hlsearch
syntax on
set is "start searching when you are typing
set go=m
set guioptions+=r
set guioptions+=t
"set guioptions+=T
set guioptions+=e
set showmode
set dy=lastline "显示最多行,不用@@
"以上是缩进相关
set ambiwidth=double
set columns=90
set background=dark
set ai "auto indent
set si "smart indent
set nu "show line number
set ruler
"colo torte
colo morning
set clipboard="+
" I haven't found how to hide this function (yet)
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()/<cr>"
endfunction
" NB: this supports "rp that replaces the selection by the contents of @r
vnoremap <silent> <expr> p <sid>Repl()
"Enable folding
"set nofen
"set fdl=0
"Misc
set wildmenu
"No sound on errors
set noerrorbells
set novisualbell
set t_vb=
"TAB RELATED
set sw=4
set ts=4
set smarttab
set et
"Editing related
set backspace=indent,eol,start
set whichwrap=h,l,~,b,s,<,>,[,]
"默认情况下, 在 VIM 中当光标移到一行最左边的时候, 我们继续按左键, 光标不能回到上一行的最右边。 同样地, 光标到了一行最右边的时候, 我们不能通过继续按右跳到下一行的最左边。 通过设置 whichwrap 我们可以对一部分按键开启这项功能。
set mouse=c "the mouse is enabled all the time
"set selectmode=
set mousemodel=popup
"set keymodel=
set selection=inclusive
set showmatch
"file type related
filetype plugin indent on
"set to auto read when a file is changed from the outside
set autoread
"中文问题
" 环境:Windows XP SP2,gVIM 7.1
set encoding=utf-8
"langua mes zh_CN.UTF-8
"source $VIMRUNTIME/delmenu.vim
set langmenu=zh_CN.UTF-8
"source $VIMRUNTIME/menu.vim
" Encoding related
set fileencodings=ucs-bom,cp936,gb18030,utf-8,big5,euc-jp,euc-kr,latin1
" encoding 是 utf-8 的时候可以设置 guifontwide
" 这样中英文就可以用不同的字体了,下面是我感觉舒服的配置
set guifont=Courier/ 10/ Pitch/ 12
set guifontwide=新宋体:h12
set linespace=2
" PS: Bitstream 是 Linux 中挖出来的,漂亮的反锯齿
"help file set to cn
if version >= 603
set helplang=cn
endif
set stal=1
set nobackup
autocmd BufReadPost * if line("'/"")&& line ("'/"") <= line("$") | exe "normal `/"" | endif
"autocmd BufEnter * call DoWordComplete()
"断行设置
"set tw=78
set lbr
"set fo+=mB
" Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
au BufWinLeave *.ztx mkview
au BufWinEnter *.ztx silent loadview
au BufNewFile,BufRead *.tx1 setf tx1
autocmd BufEnter * lcd %:p:h " 放入.vimrc自动完成上面的命令
"autocmd :Ex:q
" ============================================================================
" Shortcuts
" ============================================================================
" Move lines
nmap <C-Down> :<C-u>move .+3<CR>
nmap <C-Up> :<C-u>move .-2<CR>
imap <C-Down> <C-o>:<C-u>move .+1<CR>
imap <C-Up> <C-o>:<C-u>move .-2<CR>
vmap <C-Down> :move '>+1<CR>gv
vmap <C-Up> :move '<-2<CR>gv
" Toggle line number,display the line number on the left
nmap <C-F12> :setlocal nu!<CR>
imap <C-F12> <C-o>:setlocal nu!<CR>
" Toggle spell check, open or close spell check
" For VIM7 only
nmap <C-F11> :setlocal spell!<CR>
imap <C-F11> <C-o>:setlocal spell!<CR>
"简单编辑更新 _vimrc文件
"nmap ,v :e C:/Program Files/Vim/_vimrc<CR>
"nmap ,fe :Texplore<CR>
" CTRL-Z is Undo; not in cmdline though
noremap <C-Z> u
inoremap <C-Z> <C-O>u
" Alt-Space is System menu
if has("gui")
noremap <M-Space> :simalt ~<CR>
inoremap <M-Space> <C-O>:simalt ~<CR>
cnoremap <M-Space> <C-C>:simalt ~<CR>
endif
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
" CTRL-Tab is Next window
noremap <C-Tab> <C-PageDown>w
inoremap <C-Tab> <C-O><C-PageDown>w
cnoremap <C-Tab> <C-C><C-PageDown>w
onoremap <C-Tab> <C-C><C-PageDown>w
" CTRL-V and SHIFT-Insert are Paste
"map <C-V> "+gP
"map <S-Insert> "+gP
"cmap <C-V> <C-R>+
"cmap <S-Insert> <C-R>+
" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.
"exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
"exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
"imap <S-Insert> <C-V>
"vmap <S-Insert> <C-V>
" Use CTRL-Q to do what CTRL-V used to do
"noremap <C-Q> <C-V>
" For CTRL-V to work autoselect must be off.
" On Unix we have two selections, autoselect can be used.
if !has("unix")
set guioptions-=a
endif
" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
let tlist_cpp_settings = 'c++;c:class;f:function'
let tlist_c_settings = 'c;f:My Functions'
set pastetoggle=<F3>
"Map space to /
"wmap <space> /
"状态栏上显示函数名,非常有用
let g:Tlist_Process_File_Always=1
let g:Tlist_File_Fold_Auto_Close=1
"Map auto complete of (, ", ', [
inoremap $1 ()<esc>:let leavechar=")"<cr>i
inoremap $2 []<esc>:let leavechar="]"<cr>i
inoremap $4 {<esc>o}<esc>:let leavechar="}"<cr>O
inoremap $3 {}<esc>:let leavechar="}"<cr>i
inoremap $q ''<esc>:let leavechar="'"<cr>i
inoremap $w ""<esc>:let leavechar='"'<cr>i
au BufNewFile,BufRead *./(vim/)/@! inoremap " ""<esc>:let leavechar='"'<cr>i
au BufNewFile,BufRead *./(txt/)/@! inoremap ' ''<esc>:let leavechar="'"<cr>i
imap <m-l> <esc>:exec "normal f" . leavechar<cr>a
imap <d-l> <esc>:exec "normal f" . leavechar<cr>a
"=============================================================================
" Modes
"=============================================================================
function EnglishMode()
set imactivatekey=
set noimcmdline
set iminsert=0
set imsearch=0
setlocal spell
endfunction
command -nargs=0 EMODE call EnglishMode()
function ChineseMode()
set imactivatekey=C-space
set noimcmdline
set iminsert=2
set imsearch=2
setlocal nospell
endfunction
command -nargs=0 CMODE call ChineseMode()
function TextMode()
setlocal nocin
setlocal nosm
setlocal noai
setlocal tw=78
endfunction
command -nargs=0 TMODE call TextMode()
function CodeMode()
setlocal cin
setlocal sm
setlocal ai
setlocal tw=78
endfunction
command -nargs=0 CODEMODE call CodeMode()
"FencView Setting
let g:fencview_autodetect=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iabbrev MDATE <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
nmap <C-c> <Esc>:Setcomment<CR>
imap <C-c> <Esc>:Setcomment<CR>
vmap <C-c> <Esc>:SetcommentV<CR>
command! -nargs=0 Setcomment call s:SET_COMMENT()
command! -nargs=0 SetcommentV call s:SET_COMMENTV()
"非视图模式下所调用的函数
function! s:SET_COMMENT()
let lindex=line(".")
let str=getline(lindex)
"查看当前是否为注释行
let CommentMsg=s:IsComment(str)
call s:SET_COMMENTV_LINE(lindex,CommentMsg[1],CommentMsg[0])
endfunction
"视图模式下所调用的函数
function! s:SET_COMMENTV()
let lbeginindex=line("'<") "得到视图中的第一行的行数
let lendindex=line("'>") "得到视图中的最后一行的行数
let str=getline(lbeginindex)
"查看当前是否为注释行
let CommentMsg=s:IsComment(str)
"为各行设置
let i=lbeginindex
while i<=lendindex
call s:SET_COMMENTV_LINE(i,CommentMsg[1],CommentMsg[0])
let i=i+1
endwhile
endfunction
"设置注释
"index:在第几行
"pos:在第几列
"comment_flag: 0:添加注释符 1:删除注释符
function! s:SET_COMMENTV_LINE( index,pos, comment_flag )
let poscur = [0, 0,0, 0]
let poscur[1]=a:index
let poscur[2]=a:pos+1
call setpos(".",poscur) "设置光标的位置
if a:comment_flag==0
"插入//
exec "normal! i//"
else
"删除//
exec "normal! xx"
endif
endfunction
"查看当前是否为注释行并返回相关信息
"str:一行代码
function! s:IsComment(str)
let ret= [0, 0] "第一项为是否为注释行(0,1),第二项为要处理的列,
let i=0
let strlen=len(a:str)
while i<strlen
"空格和tab允许为"//"的前缀
if !(a:str[i]==' ' || a:str[i] == ' ' )
let ret[1]=i
if a:str[i]=='/' && a:str[i+1]=='/'
let ret[0]=1
else
let ret[0]=0
endif
return ret
endif
let i=i+1
endwhile
return [0,0] "空串处理
endfunction
""""""""""""""""""""""""""""""
" lookupfile setting
""""""""""""""""""""""""""""""
let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找
let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
let g:LookupFile_TagExpr = '"./filenametags"'
"if filereadable("./filenametags") "设置tag文件的名字
"endif
"
"nmap <silent> <F9> <Plug>LookupFile<cr>
"nmap <silent> <F10> :LUBufs<cr>
"nmap <silent> <F11> :LUWalk<cr>
"
set nofen
set fdl=0
"""""""""""""""""""""""""""""""
au FileType java inoremap <buffer> <C-t> System.out.println();<esc>hi
"Java comments
" autocmd FileType java source ~/vim_local/macros/jcommenter.vim
" autocmd FileType java let b:jcommenter_class_author='Amir Salihefendic ([email protected])'
" autocmd FileType java let b:jcommenter_file_author='Amir Salihefendic ([email protected])'
" autocmd FileType java map <buffer> <F2> :call JCommentWriter()<cr>
"
"Abbr'z
autocmd FileType java inoremap <buffer> $pr private
autocmd FileType java inoremap <buffer> $r return
autocmd FileType java inoremap <buffer> $pu public
autocmd FileType java inoremap <buffer> $i import
autocmd FileType java inoremap <buffer> $b boolean
autocmd FileType java inoremap <buffer> $v void
autocmd FileType java inoremap <buffer> $s String
"Folding
function! JavaFold()
"setl foldmethod=syntax
"setl foldlevelstart=1
"syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
" syn match foldImports //(/n/?import./+;/n/)/+/ transparent fold
"function! FoldText()
"return substitute(getline(v:foldstart), '{.*', '{...}', '')
"endfunction
"setl foldtext=FoldText()
endfunction
"au FileType java call JavaFold()
" au FileType java setl fen
au BufEnter *.sablecc,*.scc set ft=sablecc
"autocmd FileType c,cpp
"setl fdm=syntax | setl fen
"set foldenable
"set foldmethod=manual
"nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
set ruler
set rulerformat=%22(%n:%l/%L,%c%V%=%P%)
let g:ctags_statusline=1
let g:ctags_path=$ANDROID_BUILD_TOP
set path=$ANDROID_BUILD_TOP/include,$ANDROID_BUILD_TOP,.,$PATH
set tags=$ANDROID_BUILD_TOP/tags,./tags,tags
set statusline=%<%F%=%([%{Tlist_Get_Tagname_By_Line()}]/ %l,%c%V%)/ %P
set titlestring=vim/ -/ %n:%f/ %(%R%M%W/ %)%y%k
let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=1
set et ts=4 sw=4 ai
"colorscheme desert
colo underwater
"colo blazer
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
set tags=$ANDROID_BUILD_TOP/tags;./tags
set display=lastline,uhex
set title titlestring=%<%f\ %([%{Tlist_Get_Tagname_By_Line()}]%)
let g:ctags_regenerate=0
autocmd BufReadPost * TlistUpdate