dotfiles/vim/.vim/plugin/clear_whitespace.vim

17 lines
502 B
VimL
Raw Normal View History

2023-12-23 20:13:47 -07:00
" Removes trailing white space across the entire file
function! RemoveTailingWhitespace()
let l:prev_search = @/ " Search register
let l:cur_pos = getcurpos() " Cursor position
silent! %s/\V\s\+\$//
let @/ = l:prev_search " Restore search register
call setpos('.', l:cur_pos) " Move cursor back to starting place
endfunction
" Always remove tailing whitespace on write
autocmd BufWrite * call RemoveTailingWhitespace()
command! Trim call RemoveTailingWhitespace()