From 9a04b847ecb9742e9f42ae32934d0785aabba6f2 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Tue, 10 Feb 2026 08:29:41 -0800 Subject: [PATCH] Trailing whitespace fixes --- dotfiles/vimrc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dotfiles/vimrc b/dotfiles/vimrc index ec070ce..835fa8a 100644 --- a/dotfiles/vimrc +++ b/dotfiles/vimrc @@ -223,3 +223,21 @@ filetype plugin indent on " Disable bell set belloff=all + +" Fix trailing whitespace +function! SaveFixSpace() + let l:denylist = ['diff', 'patch', 'mail', 'gitcommit', 'markdown'] + if index(l:denylist, &filetype) != -1 + return + endif + let l:save = winsaveview() + " Execute the substitution on the range provided to the command + execute a:firstline . ',' . a:lastline . 's/\s\+$//e' + call winrestview(l:save) +endfunction +augroup CleanWhitespace + autocmd! + " This calls the command on the whole file (%) before writing the buffer + autocmd BufWritePre * :FixSpace +augroup END +command! -range=% FixSpace ,call SaveFixSpace()