关于vim的配置的教程 google下到处都是,详细的我自自己也将讲不出来,利用拿来主义吧,大家可以参考,讲的很详细。
一些技巧的设置.
首先我们提交到git服务器的code是有一定的规范的。
每行最后不能有空格,所以我们有办法来提醒我们做些什么。
- 高亮行末的空格
"hightlight tail whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
- 空格用灰白色显示
"hightlight the whitespace line
if &bg == "dark"
highlight BSignColor ctermfg=black ctermbg=darkmagenta guifg=white guibg=darkcyan
else
highlight BSignColor ctermbg=white ctermfg=blue guibg=grey guifg=RoyalBlue3
endif
function Blank_Sign()
let sign_number = 0
let line = 1
while line <= line('$')
if getline(line) =~ '^\s*$'
exe 'sign define SignSymbol linehl=BSignColor texthl=BSignColor'
exe 'sign place ' . sign_number . ' line=' . line . ' name=SignSymbol buffer=' . winbufnr(0)
endif
let sign_number = sign_number + 1
let line = line + 1
endwhile
endfunction
au BufRead * call Blank_Sign()
- 自动删除行末的空格
***********************************************************
"auto delete tail whitespace
autocmd BufWritePre * :call <SID>StripWhite()
fun! <SID>StripWhite()
%s/[ \t]\+$//ge
%s!^\( \+\)\t!\=StrRepeat("\t", 1 + strlen(submatch(1)) / 8)!ge
endfun
***********************************************************map <F7> :call RemoveEndEmptyLines(0)<CR>:noh<CR>:w<CR>''
autocmd BufWritePre * call RemoveEndEmptyLines(0)
function! RemoveEndEmptyLines(keep)
" 先干掉所有行尾的空格和 TAB
exe ":%s/\\s\*$//"
" 最后一行的行号
let lastline = line("$")
let n = lastline
" 一个循环 -__-
while (1)
" 得到第 n 行的内容
let line = getline(n)
" remove spaces and tabs
if (!empty(line))
break
endif
let n = n - 1
endwhile
" 好了,得到了需要删除掉的行范围
let start = n+1+a:keep
if (start < lastline)
" 执行范围删除
execute n+1+a:keep . "," . lastline . "d"
endif
endfunction
************************************************************
- 显示table 键和空格
"change table key
set listchars=tab:>-,trail:-
set list