Last active
December 17, 2015 18:49
-
-
Save caiyili/5655668 to your computer and use it in GitHub Desktop.
轻量级的vim的配置文件
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
""""""let mapleader""""" | |
let mapleader="," | |
let g:mapleader="," | |
""""""ignorecases""""" | |
set ignorecase | |
set incsearch | |
"""""show numbers""""" | |
set number | |
"""""set the tab width""""" | |
set tabstop=4 | |
set shiftwidth=4 | |
set expandtab | |
autocmd BufRead,BufNewFile *.html,*.phtml,*.htm call SetHtmlTabWidth() | |
fun! SetHtmlTabWidth() | |
set shiftwidth=2 | |
"echo "set shiftwidth to 2" | |
set tabstop=2 | |
"echo "set tabstop to 2" | |
endfun | |
""""""set foldcolumn""""" | |
set foldenable | |
"set foldcolumn=2 | |
set foldmethod=syntax | |
"set cursor line | |
set cursorline | |
""""""set indent""""" | |
set cindent | |
"""""set sidescroll""""" | |
set wrap | |
set sidescrolloff=10 | |
set sidescroll=1 | |
set scrolloff=3 | |
set listchars=extends:> | |
set listchars=precedes:< | |
""""""set buffer"""""" | |
""""""set display"""""" | |
set laststatus=2 | |
set showcmd " display incomplete commands | |
"""""map key""""" | |
nnoremap <leader>q :q<cr> | |
nnoremap <leader>qf :q!<cr> | |
nnoremap <leader>w :w<cr> | |
nnoremap <leader>wf :w!<cr> | |
nnoremap <leader>wq :wq<cr> | |
nnoremap <leader>qa :qall<cr> | |
nnoremap <leader>wa :wall<cr> | |
nnoremap <leader>r R | |
nnoremap <leader>s :source $HOME/.vimrc<cr> | |
nnoremap <leader>tn :tabnew<cr> | |
nnoremap <leader>tc :tabclose<cr> | |
nnoremap <c-Left> <c-w>Left | |
nnoremap <leader>> <c-w>5> | |
nnoremap <leader>< <c-w>5< | |
nnoremap <leader>>> <c-w>10> | |
nnoremap <leader><< <c-w>10< | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-l> <c-w>l | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-tab> gt | |
nnoremap <c-a> ggvG$ | |
vnoremap <c-c> "+y | |
" {{{ plugin - NERD_tree.vim 文件管理器 | |
" 让Tree把自己给装饰得多姿多彩漂亮点 | |
let NERDChristmasTree=1 | |
" 控制当光标移动超过一定距离时,是否自动将焦点调整到屏中心 | |
let NERDTreeAutoCenter=1 | |
" 指定书签文件 | |
let NERDTreeBookmarksFile=$VIMFILES.'\NERDTree_bookmarks' | |
" 指定鼠标模式(1.双击打开 2.单目录双文件 3.单击打开) | |
let NERDTreeMouseMode=2 | |
" 是否默认显示书签列表 | |
let NERDTreeShowBookmarks=1 | |
" 是否默认显示文件 | |
let NERDTreeShowFiles=1 | |
" 是否默认显示隐藏文件 | |
let NERDTreeShowHidden=1 | |
" 是否默认显示行号 | |
let NERDTreeShowLineNumbers=0 | |
" 窗口位置('left' or 'right') | |
let NERDTreeWinPos='left' | |
" 窗口宽度 | |
let NERDTreeWinSize=31 | |
nnoremap <Leader>tt :NERDTree<CR> | |
"}}} | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Parenthesis/bracket expanding | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
vnoremap () <esc>`>a)<esc>`<i(<esc> | |
vnoremap [] <esc>`>a]<esc>`<i[<esc> | |
vnoremap {} <esc>`>a}<esc>`<i{<esc> | |
vnoremap "" <esc>`>a"<esc>`<i"<esc> | |
vnoremap '' <esc>`>a'<esc>`<i'<esc> | |
vnoremap <> <esc>`>a><esc>`<i<<esc> | |
" Tab configuration | |
map <leader>tn :tabnew<cr> | |
map <leader>te :tabedit | |
map <leader>tc :tabclose<cr> | |
map <leader>tm :tabmove | |
map <leader>r R | |
inoremap ( <c-r>=OpenPair('(')<CR> | |
inoremap ) <c-r>=ClosePair(')')<CR> | |
inoremap { <c-r>=OpenPair('{')<CR> | |
inoremap } <c-r>=ClosePair('}')<CR> | |
inoremap [ <c-r>=OpenPair('[')<CR> | |
inoremap ] <c-r>=ClosePair(']')<CR> | |
" just for xml document, but need not for now. | |
"inoremap < <c-r>=OpenPair('<')<CR> | |
"inoremap > <c-r>=ClosePair('>')<CR> | |
function! OpenPair(char) | |
let PAIRs = { | |
\ '{' : '}', | |
\ '[' : ']', | |
\ '(' : ')', | |
\ '<' : '>' | |
\} | |
if line('$')>2000 | |
let line = getline('.') | |
let txt = strpart(line, col('.')-1) | |
else | |
let lines = getline(1,line('$')) | |
let line="" | |
for str in lines | |
let line = line . str . "\n" | |
endfor | |
let blines = getline(line('.')-1, line("$")) | |
let txt = strpart(getline("."), col('.')-1) | |
for str in blines | |
let txt = txt . str . "\n" | |
endfor | |
endif | |
let oL = len(split(line, a:char, 1))-1 | |
let cL = len(split(line, PAIRs[a:char], 1))-1 | |
let ol = len(split(txt, a:char, 1))-1 | |
let cl = len(split(txt, PAIRs[a:char], 1))-1 | |
if oL>=cL || (oL<cL && ol>=cl) | |
return a:char . PAIRs[a:char] . "\<Left>" | |
else | |
return a:char | |
endif | |
endfunction | |
function! ClosePair(char) | |
if getline('.')[col('.')-1] == a:char | |
return "\<Right>" | |
else | |
return a:char | |
endif | |
endf | |
inoremap ' <c-r>=CompleteQuote("'")<CR> | |
inoremap " <c-r>=CompleteQuote('"')<CR> | |
function! CompleteQuote(quote) | |
let ql = len(split(getline('.'), a:quote, 1))-1 | |
let slen = len(split(strpart(getline("."), 0, col(".")-1), a:quote, 1))-1 | |
let elen = len(split(strpart(getline("."), col(".")-1), a:quote, 1))-1 | |
let isBefreQuote = getline('.')[col('.') - 1] == a:quote | |
if '"'==a:quote && "vim"==&ft && 0==match(strpart(getline('.'), 0, col('.')-1), "^[\t ]*$") | |
" for vim comment. | |
return a:quote | |
" elseif "'"==a:quote && 0==match(getline('.')[col('.')-2], "[a-zA-Z0-9]") | |
" " for Name's Blog. | |
" return a:quote | |
elseif (ql%2)==1 | |
" a:quote length is odd. | |
return a:quote | |
elseif ((slen%2)==1 && (elen%2)==1 && !isBefreQuote) || ((slen%2)==0 && (elen%2)==0) | |
return a:quote . a:quote . "\<Left>" | |
elseif isBefreQuote | |
return "\<Right>" | |
else | |
return a:quote . a:quote . "\<Left>" | |
endif | |
endfunction | |
inoremap <CR> <c-r>=AutoIndentAfterBrace()<CR> | |
function! AutoIndentAfterBrace() | |
let leftchar = getline('.')[col('.')-2] | |
if '{'==leftchar || '('==leftchar | |
return "\<CR>\<CR>\<UP>\<Tab> " | |
else | |
return "\<CR>" | |
endif | |
endfunction | |
" ------------------------------------------------------------------ | |
" Desc: OmniCppComplete | |
" ------------------------------------------------------------------ | |
" set Ctrl+j in insert mode, like VS.Net | |
imap <unique> <C-j> <C-X><C-O> | |
" :inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>" | |
" set completeopt as don't show menu and preview | |
au FileType c,cpp,hlsl set completeopt=menuone | |
" use global scope search | |
let OmniCpp_GlobalScopeSearch = 1 | |
" 0 = namespaces disabled | |
" 1 = search namespaces in the current buffer | |
" 2 = search namespaces in the current buffer and in included files | |
let OmniCpp_NamespaceSearch = 1 | |
" 0 = auto | |
" 1 = always show all members | |
let OmniCpp_DisplayMode = 1 | |
" 0 = don't show scope in abbreviation | |
" 1 = show scope in abbreviation and remove the last column | |
let OmniCpp_ShowScopeInAbbr = 0 | |
" This option allows to display the prototype of a function in the abbreviation part of the popup menu. | |
" 0 = don't display prototype in abbreviation | |
" 1 = display prototype in abbreviation | |
let OmniCpp_ShowPrototypeInAbbr = 1 | |
" This option allows to show/hide the access information ('+', '#', '-') in the popup menu. | |
" 0 = hide access | |
" 1 = show access | |
let OmniCpp_ShowAccess = 1 | |
" This option can be use if you don't want to parse using namespace declarations in included files and want to add namespaces that are always used in your project. | |
let OmniCpp_DefaultNamespaces = ["std"] | |
" Complete Behaviour | |
let OmniCpp_MayCompleteDot = 0 | |
let OmniCpp_MayCompleteArrow = 0 | |
let OmniCpp_MayCompleteScope = 0 | |
" When 'completeopt' does not contain "longest", Vim automatically select the first entry of the popup menu. You can change this behaviour with the OmniCpp_SelectFirstItem option. | |
let OmniCpp_SelectFirstItem = 0 | |
" ------------------------------------------------------------------ | |
" Desc: pythoncomplete | |
" ------------------------------------------------------------------ | |
" DISABLE: au FileType python set completeopt=menuone,preview | |
" NOTE: the preview can show the internal document in a preview window, but I don't think it have too much help | |
au FileType python set completeopt=menuone | |
filetype plugin indent on | |
set completeopt=longest,menu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment