windows下常用的_vimrc配置

效果圖

配置 

set nocompatible	"set compatible讓 vim 關閉所有擴展的功能,儘量模擬 vi 的行爲但這樣就不應用 vim 的很多強大功能,所以一般沒有什麼特殊需度要的話(比如執行很老的 vi 腳本),都要在 vim 的配置開始,寫上 set nocompatible,關閉兼容模式。由於這個選項是最最基礎的選項,會連帶很多其它選項發生變動(稱作副作用),所以它必需是第一個設定的選項。
set imcmdline

"gvim內部編碼
set encoding=utf8
set langmenu=zh_CN.utf-8
language message zh_CN.UTF-8	"解決Console輸出亂碼

set termencoding=utf-8
"當前編輯的文件編碼
set fileencoding=chinese
"gvim打開支持編碼的文件
set fileencodings=ucs-bom,utf-8,chinese

"解決菜單亂碼
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

"引用一些默認配置
source $VIMRUNTIME/vimrc_example.vim

"模仿win快捷鍵,如:Ctrl+A全選、Ctrl+c複製、Ctrl+v粘貼等等
"source $VIMRUNTIME/mswin.vim
"behave mswin
" Vim 的默認寄存器和系統剪貼板共享
set clipboard+=unnamed
"自動最大化
"au GUIEnter * simalt ~x
"設置字體和字號
set guifont=Courier_New:b:h18:w9.5
set guifontwide=NSimSun:b:h18	"新宋體
"配色方案
colors notepad-plus-plus

"防止特殊符號無法正常顯示
set ambiwidth=double

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

"Persistent undo
if has ('persistent_undo')
	set undodir=~/.vim/undodir
	set undofile
	set undolevels=1000 “maximum number of changes that can be undone
	set undoreload=10000 “maximum number lines to save for undo on a buffer reload
endif

"撤銷列表
"undo list
"自動隱藏沒有保存的緩衝區,切換buffer時不給出保存當前buffer的提示
set hidden

"在.vim/syntax/c.vim文件中設置了運算符,函數名等高亮後,可以:
"syntax enable            "打開語法高亮
syntax on                "打開語法高亮

"開啓自動縮進
set autoindent
set smartindent
set cindent

"Tab轉換成Space
"set expandtab
set noexpandtab
"將Tab解析爲4個空白
set tabstop=4
"Tab寬度
set shiftwidth=4
"按一次backspace就刪除4個空格,僅僅在前面沒有字符的情況起作用
set smarttab

"大小寫匹配
set ignorecase smartcase
"modeline可以讓你針對每個文件進行文件級別的設置,這些設置是覆蓋當前用戶的vimrc中的設置的。當vim打開一個包含了vim modeline註釋行的文件時,會自動讀取這一行的參數配置並調整自己的設置到這個配置。
set modeline

"工具欄和菜單欄
set guioptions+=T
set guioptions+=m
"右側滾動條
set guioptions-=r

"set nowrap	"關閉自動換行
set wrap
set linebreak            "整詞換行,與自動換行搭配使用,效果很好
set backspace=indent,eol,start	"支持BackSpace

"狀態欄
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]    "顯示文件名: 總行數, 總的字符數
set ruler		 "在編輯過程中, 在右下角顯示光標位置的狀態行

set showmatch	"顯示匹配
set noswapfile

"不保留備份文件,但寫入期間有備份
set writebackup
set nobackup
set noswapfile	"緩衝區使用交換文件

set hlsearch	"搜索高亮
set incsearch	"打開顯示查找匹配過程
set wrapscan	"搜索繞回
set nu		"行號
set scrolloff=5         "在光標接近底端或頂端時,自動下滾或上滾
set autochdir            "自動設置當前目錄爲正在編輯的目錄

"可以把需要開啓的鍵的代號寫到 whichwrap 的參數列表中, 各個鍵之間使用逗號分隔。
"以下是 whichwrap 支持的按鍵名稱列表:
"b: 在 Normal 或 Visual 模式下按 除(Backspace)鍵。 s: 在 Normal 或 Visual 模式下按空 鍵。 h: 在 Normal 或 Visual 模式下按 h 鍵。 l: 在 Normal 或 Visual 模式下按 l 鍵。 <: 在 Normal 或 Visual 模式下按左方向鍵。 >: 在 Normal 或 Visual 模式下按右方向鍵。 ~: 在 Normal 模式下按 ~ 鍵(翻轉當前字母大小寫)。 [: 在 Insert 或 Replace 模式下按左方向鍵。 ]: 在 Insert 或 Replace 模式下按右方向鍵。
set whichwrap=b,s,h,l,<,>,[,]    "光標可以從行首和行尾跳到另一行去

map <MiddleMouse> <Nop>
imap <MiddleMouse> <Nop>
map <2-MiddleMouse> <Nop>
imap <2-MiddleMouse> <Nop>
map <3-MiddleMouse> <Nop>
imap <3-MiddleMouse> <Nop>
map <4-MiddleMouse> <Nop>
imap <4-MiddleMouse> <Nop>

set tags=tags;

set mouse=a
set autowriteall
set cino=g1h1i2:0
run cscope.vim

hi Normal guibg=#CBE8CA

map <C-g> :BufExplorer<CR>
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1

autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
au FileType c,cc,cpp,h setlocal comments-=:// comments+=f://

autocmd FileType c,cc,cpp,h,js,lua,java set expandtab | set shiftwidth=4

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章