vimrc的完全版本

" -------------------- Copyright Header Begin ---------------------------------
" Description :  Facilitates vim settings 
" Version     :  2.0.1
" Author      :  RollStone,[email protected]
" Copyright   :  RollStone (2007-2014).
" LastChanged :  2014-10-14 00:45:09
" -------------------- Copyright Header End -----------------------------------
" Overview for maintainers :
" The file is divided into following sections. You may add yours or update these
" if/when you choose to enhance this setting file.
"
" + General Settings
" + Tips(just need to how use these functions)
" + Autocmds
" + Plugins 
" + Mappings
"{{{ ---------------- General Settings Begin ---------------------------------
"MC: My Contaction
"abbr mc RollStone,[email protected]

"Leader
let g:mapleader=‘,‘

"Just more like vim,less vi
set nocompatible

"backup
set nobackup
"colorscheme
set t_Co=256
colorscheme peaksea
if &diff
	colorscheme peaksea
endif

"dirs
set autochdir
set autoread
set autowrite

"complete
set complete+=k
"set wildmenu
set completeopt=longest,menu
set formatoptions+=mM
set cinoptions=:0,l1,t0,g0
set nosmd
set nosc

"encodings
set fileencodings=utf-8,gbk,gb18030,chinese

"indent
set autoindent
set smartindent
set noexpandtab
set tabstop=4
set shiftwidth=4

"search
set incsearch
set hlsearch
set ignorecase

"statusline
set laststatus=2

"tabulation
set ruler
set number
set list lcs=tab:\¦\ 

"wrap
set nowrap
set nowrapscan

"others
set backspace=indent,eol,start
set wildignore=*.bak,*.o,*.e,*~
set browsedir=current
set sessionoptions-=curdir
set ttimeoutlen=100
set vb t_vb=

"some common gates
syntax on
filetype plugin indent on
"}}} ---------------- General Settings End -----------------------------------

" Tips {{{1
"notice: n just be in normal mode
"tip1. match ()/{}/[]
"n: % (first chang into normal mode,and press shift + 5)

"tip2. find the manual content
"n: K (first chang into normal mode,and press shift + K)

"tip3. return prev window after ‘gf‘
"n:<ctrl-o>

"tip4. check what options
"c: set [all]

" Autocmds {{{1
if has("autocmd")
	"when modifies vimrc or .vimrc reload it
	au BufWritePost [ _.]vimrc source ~/.vimrc
	"auto chdir to curdir
	au BufEnter * :lchdir %:p:h
	"change to the lastest cursor position
	au BufReadPost * if line("‘\"") > 0 && line("‘\"") <= line("$") | exe "normal! g`\"" | endif 
endif " has (autocmd)"

" Plugins {{{1
"c.vim(c-support)
let g:C_MapLeader=‘;‘

"powerline
let g:Powerline_cache_dir=simplify(expand(‘%:p:h‘))
let g:Powerline_cache_enabled=0
"let g:Powerline_dividers_override = [‘>>‘, ‘>‘, ‘<<‘, ‘<‘]

"overrid mode_name"
let g:Powerline_mode_n=‘n‘
let g:Powerline_mode_i=‘i‘
let g:Powerline_mode_v=‘V‘
let g:Powerline_mode_R=‘R‘
let g:Powerline_stl_path_style=‘full‘

"taglist
let Tlist_Auto_Open=0
let Tlist_WinWidth=38
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=0
let Tlist_Close_On_Select=1
let Tlist_File_Fold_Auto_Close = 0
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Display_Prototype = 1

"windowmanager
let g:winManagerWidth=g:Tlist_WinWidth
let g:winManagerWindowLayout=‘TagList|FileExplorer‘
let g:wiw=60
nmap wm :WMToggle<cr>

""}}} ----------------- Plugins End --------------------------------------------

"---------------- Mappings Begin -----------------------------------------{{{1 
"F1 - overrule Linux F1
map <silent> <F1> <esc>:exec "help ".expand("<cword>")<cr>

"F2 - call file explorer Ex
map  <silent> <F2>        :Explorer
imap <silent> <F2>   <esc>:Explorer

"F3 - remove trail white-space
map  <silent> <F3>        :%s/[ \t\r]\+$//g<cr>
imap <silent> <F3>   <esc>:%s/[ \t\r]\+$//g<cr>

"F5-F8 :quickfix :open/close error windows,display prev/next error
map  <silent> <F5>        :copen<cr>
map  <silent> <F6>        :cclose<cr>
map  <silent> <F7>        :cp<cr>
map  <silent> <F8>        :cn<cr>
imap <silent> <F5>   <esc>:copen<cr>
imap <silent> <F6>   <esc>:cclose<cr>
imap <silent> <F7>   <esc>:cp<cr>
imap <silent> <F8>   <esc>:cn<cr>

"autocomplete parenthesis, brackets and braces
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
vnoremap ( s()<Esc>P<Right>%
vnoremap [ s[]<Esc>P<Right>%
vnoremap { s{}<Esc>P<Right>%
inoremap , , 

"Open includes files in a new split window
set path=.,include,../include,/usr/include,/usr/local/include
"nmap gf <c-w><c-f>

"{{User defines functions and its‘ map

"Format C/CPP codes,and return current line
function! UDFormatCppCode()
	silent exec "ks| normal gg=G|‘s"
endfunc
nmap fmt :call UDFormatCppCode()<cr>
imap fmt <esc>:call UDFormatCppCode()<cr>o
au BufWritePre,FileWritePre *.c,*.cpp,*.h,*.hpp,*.java :call UDFormatCppCode()

"Author Info Adder
function! UDAuthorInfoAdd()
	let aid_author=‘RollStone‘
	let aid_email=‘[email protected]‘
	let fts=expand(‘%:p:e‘)
	if fts == ‘sh‘ || fts == ‘pl‘
	"script file
		call setline(1,[‘#=============================================================‘
				\,‘#   Filename:  ‘.expand(‘%:t‘)
				\,‘#      Brief:  TODO ‘
				\,‘#     Author:  ‘.aid_author
				\,‘#      Email:  ‘.aid_email
				\,‘# LastChange:  ‘.strftime(‘%F %T‘)
				\,‘#   Revision:  ‘
				\,‘#=============================================================‘])
		"add FileHeader first line 
		let line=getline(0)
		if line !~ ‘^\#\!\/bin\/.*$‘
			let lstr=expand(‘%:p:e‘)
			if lstr == ‘sh‘
				let newline= ‘#!/bin/bash‘
			elseif lstr == ‘pl‘
				let newline= ‘#!/bin/perl‘
			endif
			call append(0,newline)
		endif
	else
	"elseif fts == ‘c‘ || fts ==‘h‘ || fts =~ ‘\*pp‘ || fts == ‘java‘
	"program files
		let line=getline(0)
		if line !~ ‘^\/\*.*$‘
			call append(0,[‘/*‘
				\,‘*==============================================================================‘
				\,‘*   Filename:  ‘.expand(‘%:t‘)
				\,‘*      Brief:  TODO ‘
				\,‘*     Author:  ‘.aid_author
				\,‘*      Email:  ‘.aid_email
				\,‘* LastChange:  ‘.strftime(‘%F %T‘)
				\,‘*   Revision:  ‘
				\,‘*==============================================================================‘
				\,‘*/‘])
		endif
	endif
	echohl WarningMsg | echo "Success to add FileHeader" | echohl None
endfunc
"Author Info Detect
function! UDAuthorInfoDetect()
	let n=1
	let updated=0
	while n<20
		let line=getline(n)
		if line =~ ‘^.*ile.ame.*:*.*$‘
			let newline=substitute(line,‘:.*$‘,‘:  ‘.expand(‘%:t‘),‘g‘)
			call setline(n,newline)
			let updated = 1
		elseif line =~ ‘^.*hange.*:\S*.*$‘
			let newline=substitute(line,‘:.*$‘,‘:  ‘.strftime("%Y-%m-%d %H:%M:%S"),‘g‘)
			call setline(n,newline)
			let updated = 1
		endif
		let n+=1
	endwhile
	"
	if updated == 1
		echohl WarningMsg | echo "Success to update FileHeader." | echohl None
	else
		call UDAuthorInfoAdd()
	endif
endfunc

nmap udaid :call UDAuthorInfoAdd()<cr>
imap udaid <esc>:call UDAuthorInfoAdd()<cr>$a
"update last modified changes
au BufNewFile *.sh,*.pl,*.txt,*.java,*.go :call UDAuthorInfoAdd()
au BufWrite,FileWritePre,FileAppendPre *vimrc,*.sh,*.pl,*.h,*.c,*.*pp :call UDAuthorInfoDetect()

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。