“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
”
” Author: sunboy_2050
” Version: 1.0
” Last Change: 2011-11-11 11:11:11
” http://blog.csdn.net/sunboy_2050
”
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
” General
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
“Get out of VI’s compatible mode..
set nocompatible
” Platform
function! MySys()
return “linux”
endfunction
“Sets how many lines of history VIM har to remember
set history=400
” Chinese
if MySys() == “windows”
“set encoding=utf-8
“set langmenu=zh_CN.UTF-8
“language message zh_CN.UTF-8
“set fileencodings=ucs-bom,utf-8,gb18030,cp936,big5,euc-jp,euc-kr,latin1
endif
“Enable filetype plugin
filetype plugin on
filetype indent on
“Set to auto read when a file is changed from the outside
set autoread
“Have the mouse enabled all the time:
set mouse=a
“Set mapleader
let mapleader = “,”
let g:mapleader = “,”
“Fast saving
nmap ww :w
nmap wf :w!
“Fast quiting
nmap qw :wq
nmap qf :q!
nmap qq :q
nmap qa :qa
“Fast remove highlight search
nmap :noh
“Fast redraw
nmap rr :redraw!
” Switch to buffer according to file name
function! SwitchToBuf(filename)
“let fullfn = substitute(a:filename, “^\~/”,
HOME.“/”,“”)”findincurrenttabletbufwinnr=bufwinnr(a:filename)ifbufwinnr!=−1execbufwinnr.“wincmdw”returnelse”findineachtabtabfirstlettab=1whiletab<=tabpagenr(“
”)
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec “normal ” . tab . “gt”
exec bufwinnr . “wincmd w”
return
endif
tabnext
let tab = tab + 1
endwhile
” not exist, new tab
exec “tabnew ” . a:filename
endif
endfunction
“Fast edit vimrc
if MySys() == ‘linux’
“Fast reloading of the .vimrc
map ss :source ~/.vimrc
“Fast editing of .vimrc
map ee :call SwitchToBuf(“~/.vimrc”)
“When .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
elseif MySys() == ‘windows’
” Set helplang
set helplang=cn
“Fast reloading of the _vimrc
map ss :source ~/_vimrc
“Fast editing of _vimrc
map ee :call SwitchToBuf(“~/_vimrc”)
“When _vimrc is edited, reload it
autocmd! bufwritepost _vimrc source ~/_vimrc
“Fast copying from linux
func! CopyFromZ()
autocmd! bufwritepost _vimrc
exec ‘split y:/.vimrc’
exec ‘normal 17G’
exec ‘s/return “linux”/return “windows”/’
exec ‘w! ~/_vimrc’
exec ‘normal u’
exec ‘q’
endfunc
nnoremap uu :call CopyFromZ():so ~/_vimrc
endif
” For windows version
if MySys() == ‘windows’
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
endif
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
” Colors and Fonts
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“
“Set font
“if MySys() == “linux”
” set gfn=Monospace\ 11
“endif
” Avoid clearing hilight definition in plugins
if !exists(“g:vimrc_loaded”)
“Enable syntax hl
syntax enable
" color scheme
if has("gui_running")
set guioptions-=T
set guioptions-=m
set guioptions-=L
set guioptions-=r
colorscheme darkblue_my
"hi normal guibg=#294d4a
else
"colorscheme desert_my"
endif " has
endif ” exists(…)
“Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map 1 :set syntax=c
map 2 :set syntax=xhtml
map 3 :set syntax=python
map 4 :set ft=javascript
map $ :syntax sync fromstart
autocmd BufEnter * :syntax sync fromstart
“Highlight current
“if has(“gui_running”)
” set cursorline
” hi cursorline guibg=#333333
” hi CursorColumn guibg=#333333
“endif
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
” Fileformats
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
“Favorite filetypes
set ffs=unix,dos
nmap fd :se ff=dos
nmap fu :se ff=unix
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
” VIM userinterface
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
“Set 7 lines to the curors - when moving vertical..
“set so=7
” Maximum window when GUI running
if has(“gui_running”)
set lines=9999
set columns=9999
endif
“Turn on WiLd menu
set wildmenu
“Always show current position
set ruler
“The commandbar is 2 high
set cmdheight=2
“Show line number
set nu
“Do not redraw, when running macros.. lazyredraw
set lz
“Change buffer - without saving
“set hid
“Set backspace
set backspace=eol,start,indent
“Bbackspace and cursor keys wrap to
“set whichwrap+=<,>,h,l
set whichwrap+=<,>
“Ignore case when searching
“set ignorecase
“Include search
set incsearch
“Highlight search things
set hlsearch
“Set magic on
set magic
“No sound on errors.
set noerrorbells
set novisualbell
set t_vb=
“show matching bracets
“set showmatch
“How many tenths of a second to blink
“set mat=2
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”
” Statusline
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”
“Always hide the statusline
set laststatus=2
function! CurDir()
let curdir = substitute(getcwd(), ‘/home/easwy/’, “~/”, “g”)
return curdir
endfunction
“Format the statusline
“set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”
” Visual
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”
” From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @”
execute “normal! vgvy”
let l:pattern = escape(@”, ‘\/.*
[]′)letl:pattern=substitute(l:pattern,“\n
”, “”, “”)
if a:direction == ‘b’
execute “normal ?” . l:pattern . “^M”
else
execute “normal /” . l:pattern . “^M”
endif
let @/ = l:pattern
let @” = l:saved_reg
endfunction
“Basically you press * or # to search for the current selection !! Really useful
vnoremap * :call VisualSearch(‘f’)
vnoremap # :call VisualSearch(‘b’)
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
” Moving around and tabs
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“””
“Map space to / and c-space to ?
“map /
“map ?
“Smart way to move btw. windows
nmap j
nmap k
nmap h
nmap l
“Actually, the tab does not switch buffers, but my arrows
“Bclose function can be found in “Buffer related” section
map bd :Bclose
“map bd
“Use the arrows to something usefull
“map :bn
“map :bp
“Tab configuration
map tn :tabnew
map te :tabedit
map tc :tabclose
map tm :tabmove
try
set switchbuf=useopen
set stal=1
catch
endtry
“Moving fast to front, back and 2 sides ;)
imap