3 ms·
"Many people like to remove any extra whitespace from the " ends of lines. Here is one way to do it automatically " when saving file. fun! <SID>StripTrail
by njharman 16y ago
"Many people like to remove any extra whitespace from the
" ends of lines. Here is one way to do it automatically
" when saving file.
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" When editing a file, always jump to the last known cursor position.
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif
" This function determines, wether we are on the start of the line text (then tab indents)
" or if we want to try autocompletion
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" Remap the tab key to select action with InsertTabWrapper
inoremap <tab> <c-r>=InsertTabWrapper()<cr>