常用vim的話,或多或少會不小在行末多按了幾個空白,或是在檔尾多了幾個空行。作者Vigil寫了一個去除這些東西的function:
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
function RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
將這個function加入/etc/vim/vimrc即可。試用了一下,真不錯~感謝Vigil.
全站熱搜
留言列表