Skip to content

Instantly share code, notes, and snippets.

@seanpianka
Last active October 22, 2019 17:17
Show Gist options
  • Save seanpianka/4811d02671a55bf8aeedd76e4a46e1a4 to your computer and use it in GitHub Desktop.
Save seanpianka/4811d02671a55bf8aeedd76e4a46e1a4 to your computer and use it in GitHub Desktop.
vim: delete all trailing whitespace from files matching certain patterns using vimscript
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
for suffix in ["py", "js", "css", "cpp", "c", "h", "hpp", "rs", "groovy", "groovy.j2"]
execute 'autocmd BufWrite *.'.suffix.' :call DeleteTrailingWS()'
endfor
for prefix in ["Jenkinsfile"]
execute 'autocmd BufWrite '.prefix.'* :call DeleteTrailingWS()'
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment