整理和弄出自己的vimrc,也為了讓gvim上看的字體更大一些,閱讀起來比較容易,也弄了gvimrc的設定檔。 成品GVIM看起來大概會像這樣 (圖片內容有簡單的介面介紹)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Gvim 專用設定檔 | |
" 設定顏色 | |
"color torte | |
colorscheme ir_black | |
set t_Co=256 | |
" 設定字型 | |
set guifont=Consolas:h16 | |
" 設定寬度 | |
set columns=90 | |
" Make command line two lines high | |
set ch=2 | |
" Hide the mouse when typing text | |
set mousehide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" **********熱鍵設定區********** | |
" 樹狀檔案列表 NERD Tree | |
map <F2> :NERDTreeToggle<CR> | |
" 最近使用檔案列表(MRU) | |
map <s-F2> :MRU<CR> | |
" Tag list | |
map <F3> :TlistToggle<CR> | |
" Update file | |
"map <F4> :up<CR> | |
" Save all buffer files | |
"nmap <s-F4> :wall<CR> | |
" Clear last used search hightlighting | |
nnoremap <silent> <C-l> :nohl<CR><C-l> | |
" AutoComple Open or close | |
imap <F6> <ESC>:AutoComplPopDisable<CR> | |
imap <s-F6> <ESC>:AutoComplPopEnable<CR> | |
" Setup SrcExplToggle | |
map <F7> :SrcExplToggle<CR> | |
" 呼叫 HexMode 做16進位顯示 | |
nnoremap <C-H> :Hexmode<CR> | |
inoremap <C-H> <Esc>:Hexmode<CR> | |
vnoremap <C-H> :<C-U>Hexmode<CR> | |
" 呼叫 vim menu | |
source $VIMRUNTIME/menu.vim | |
set wildmenu | |
set cpo-=< | |
set wcm=<C-Z> | |
map <s-F3> :emenu <C-Z> | |
" // The switch of the Source Explorer | |
nmap <F4> :SrcExplToggle<CR> | |
" // Set the height of Source Explorer window | |
let g:SrcExpl_winHeight = 8 | |
" // Set 100 ms for refreshing the Source Explorer | |
let g:SrcExpl_refreshTime = 100 | |
" // Set "Enter" key to jump into the exact definition context | |
" let g:SrcExpl_jumpKey = "<ENTER>" | |
" // Set "Space" key for back from the definition context | |
let g:SrcExpl_gobackKey = "<SPACE>" | |
" // In order to Avoid conflicts, the Source Explorer should know what plugins | |
" // are using buffers. And you need add their bufname into the list below | |
" // according to the command ":buffers!" | |
let g:SrcExpl_pluginList = [ | |
\ "__Tag_List__", | |
\ "_NERD_tree_", | |
\ "Source_Explorer" | |
\ ] | |
" // Enable/Disable the local definition searching, and note that this is not | |
" // guaranteed to work, the Source Explorer doesn't check the syntax for now. | |
" // It only searches for a match with the keyword according to command 'gd' | |
let g:SrcExpl_searchLocalDef = 1 | |
" // Do not let the Source Explorer update the tags file when opening | |
let g:SrcExpl_isUpdateTags = 0 | |
" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to | |
" // create/update a tags file | |
let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ." | |
" // Set "<s-F4>" key for updating the tags file artificially | |
let g:SrcExpl_updateTagsKey = "<s-F4>" | |
" Buffer Explorer / Browser key | |
" '\be' (normal open) or | |
" '\bs' (force horizontal split open) or | |
" '\bv' (force vertical split open) | |
" Comment Mode 也可用 bash 的key binding | |
cmap <c-a> <home> | |
cmap <c-e> <end> | |
cnoremap <c-b> <left> | |
cnoremap <c-d> <del> | |
cnoremap <c-f> <right> | |
cnoremap <c-n> <down> | |
cnoremap <c-p> <up> | |
cnoremap <esc><c-b> <s-left> | |
cnoremap <esc><c-f> <s-right> | |
" 分頁移動設定 | |
"map tn :tabnext<CR> | |
"map tp :tabprev<CR> | |
map te :tabnew | |
map tc :tabclose<CR> | |
" Normal Mode時,可用tab及shift-Tab做縮排 | |
nmap <tab> v> | |
nmap <s-tab> v< | |
" Visual/Select Mode時,也行 | |
vmap <tab> >gv | |
vmap <s-tab> <gv | |
" 上下移動行內容 | |
nnoremap <A-j> :m+<CR>== | |
nnoremap <A-k> :m-2<CR>== | |
inoremap <A-j> <Esc>:m+<CR>==gi | |
inoremap <A-k> <Esc>:m-2<CR>==gi | |
vnoremap <A-j> :m'>+<CR>gv=gv | |
vnoremap <A-k> :m-2<CR>gv=gv | |
" **********環境設定區********** | |
" 設定背景顏色為黑色 | |
set background=dark | |
" colors darkblue | |
" 關閉 vi 兼容模式 | |
set nocompatible | |
" Set mouse | |
set mouse=a | |
" 打開語法效果 | |
syntax on | |
" 依檔名打開語法效果 | |
filetype on | |
" 自動寫入buffer狀態 | |
set autowrite | |
" 顯示行號 | |
set number | |
" Show command line | |
set showcmd | |
" 設定tab顯示符號 空白顯示符號 | |
set lcs=tab:>-,trail:- | |
" 顯示製表位(^I)和行尾標誌($) | |
set list | |
" 顯示現在的模式 | |
set showmode | |
"沒有備份檔案 | |
set nobackup | |
" 自動設定標題 | |
set title | |
" 設定 tab 對齊的字元數 | |
set tabstop=4 | |
" 狀態列顯示游標所在處之行列狀態 | |
set ruler | |
" 自動縮排 | |
set autoindent | |
" 聰明的縮排 | |
set smartindent | |
" 用空白來當作tab | |
set expandtab | |
" 自動縮排為以四空格為基準 | |
set shiftwidth=4 | |
set smarttab | |
set fdm=indent | |
set fdc=4 | |
" 設定自動換行 | |
set wrap | |
" 尋找時,符合字串會反白表示 | |
set hlsearch | |
" 加強式尋找功能,在鍵入 patern 時會立即反應移動至目前鍵入之 patern 上 | |
set incsearch | |
" 底下的command status line為兩行 | |
set cmdheight=2 | |
" 總是顯示資訊 | |
set laststatus=2 | |
" Line highlight 設此是游標整行會標註顏色 | |
set cursorline | |
" Column highlight 設此是遊標整列會標註顏色 | |
"set cursorcolumn | |
" 自動重新載入vimrc | |
autocmd! BufWritePost .vimrc source % | |
autocmd! BufWritePost .gvimrc source % | |
autocmd! BufWritePost _vimrc source % | |
autocmd! BufWritePost _gvimrc source % | |
" 設定最後編輯的位置,再次開檔案就會移動到那行 | |
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif | |
" 設定狀態列訊息 | |
highlight User1 ctermfg=red | |
highlight User2 term=underline cterm=underline ctermfg=green | |
highlight User3 term=underline cterm=underline ctermfg=yellow | |
highlight User4 term=underline cterm=underline ctermfg=white | |
highlight User5 ctermfg=cyan | |
highlight User6 ctermfg=white | |
" %1* -> User1's highlight, %2*->User2's highlight | |
" = -> Separation point between left and right aligned items. | |
" < -> Where to truncate line if too long. Default is at the start. | |
set statusline=%4*%<\ %1*[%F] | |
set statusline+=%4*\ %5*[%{&encoding}, " encoding | |
set statusline+=%{&fileformat}]%m " file formatoptions | |
" 設定GitBranch前置字串 | |
let g:git_branch_status_text=" " | |
" 設定GitBranch讀不到時顯示字串 | |
let g:git_branch_status_nogit="" | |
set statusline+=%{GitBranchInfoString()} | |
set statusline+=%4*%=\ %6*%y%4*\ %3*%l%4*,\ %3*%c%4*\ \<\ %2*%P%4*\ \> | |
" 設定檔案編碼清單 | |
set fencs=utf-8,big5,bgk,euc-jp,utf-16le | |
" 設定編碼 | |
set fenc=utf-8 | |
" 內部編碼 | |
set enc=utf-8 | |
" Terminal編碼 | |
set tenc=utf-8 | |
" 設定自動折合模式 | |
set foldmethod=syntax | |
" 方便中文重排設定 | |
set formatoptions=mtcql | |
" 將註解由深藍色變綠色 | |
hi Comment ctermfg=Green | |
" taglist config | |
let Tlist_Use_Right_Window=1 | |
let Tlist_File_Fold_Auto_Close=1 | |
" 設定 Omni completion | |
autocmd FileType c set ofu=ccomplete#Complete | |
autocmd FileType cpp set ofu=cppcomplete#Complete | |
autocmd FileType php set ofu=phpcomplete#CompletePHP | |
autocmd FileType python set ofu=pythoncomplete#Complete | |
autocmd FileType javascript set ofu=javascriptcomplete#CompleteJS | |
autocmd FileType html set ofu=htmlcomplete#CompleteTags | |
autocmd FileType css set ofu=csscomplete#CompleteCSS | |
autocmd FileType xml set ofu=xmlcomplete#CompleteTags | |
" tags config | |
set tags+=./tags | |
" c autotidy by indent | |
autocmd FileType c :set equalprg=indent | |
" Folding : http://vim.wikia.com/wiki/Syntax-based_folding see comment by Ostrygen | |
au FileType cs set omnifunc=syntaxcomplete#Complete | |
au FileType cs set foldmethod=marker | |
au FileType cs set foldmarker={,} | |
au FileType cs set foldtext=substitute(getline(v:foldstart),'{.*','{...}',) | |
au FileType cs set foldlevelstart=2 | |
" Quickfix mode: command line msbuild error format | |
au FileType cs set errorformat=\ %#%f(%l\\\,%c):\ error\ CS%n:\ %m | |
" **********功能區********** | |
" clever tab completion | |
fun! KeywordComplete() | |
let left = strpart(getline('.'), col('.') - 2, 1) | |
if left =~ "^$" | |
return "\<Tab>" | |
elseif | |
left =~ ' $' | |
return "\<Tab>" | |
else | |
return "\<C-N>" | |
endfun | |
inoremap <silent> <Tab> <C-R>=KeywordComplete() | |
fun! OmniComplete() | |
let left = strpart(getline('.'), col('.') - 2, 1) | |
if left =~ "^$" | |
return "" | |
elseif left =~ ' $' | |
return "" | |
else | |
return "\<C-x>\<C-o>" | |
endfun | |
inoremap <silent> <S-Tab> <C-R>=OmniComplete() | |
" ex command for toggling hex mode - define mapping if desired | |
command -bar Hexmode call ToggleHex() | |
" helper function to toggle hex mode | |
function! ToggleHex() | |
" hex mode should be considered a read-only operation | |
" save values for modified and read-only for restoration later, | |
" and clear the read-only flag for now | |
let l:modified=&mod | |
let l:oldreadonly=&readonly | |
let &readonly=0 | |
let l:oldmodifiable=&modifiable | |
let &modifiable=1 | |
if !exists("b:editHex") || !b:editHex | |
" save old options | |
let b:oldft=&ft | |
let b:oldbin=&bin | |
" set new options | |
setlocal binary " make sure it overrides any textwidth, etc. | |
let &ft="xxd" | |
" set status | |
let b:editHex=1 | |
" switch to hex editor | |
%!xxd | |
else | |
" restore old options | |
let &ft=b:oldft | |
if !b:oldbin | |
setlocal nobinary | |
endif | |
" set status | |
let b:editHex=0 | |
" return to normal editing | |
%!xxd -r | |
endif | |
" restore values for modified and read only state | |
let &mod=l:modified | |
let &readonly=l:oldreadonly | |
let &modifiable=l:oldmodifiable | |
endfunction | |
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 | |
" Smooth scrolling | |
map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y> | |
map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E> | |
" vim: ts=2: |
- Mac OSX
- Vim 7.2.22
- GVim 7.2.160
1 comments:
投影片寫的真好,讓我對於Vim有更深刻的了解了,謝謝分享這麼好的投影片跟vimrc設定以及說明.