A function and autocommand pair that removes all trailing whitespace and all empty lines at the end of the buffer on every BufWritePre.
BufWritePre
https://user-images.githubusercontent.com/59481467/138811091-05031eb1-96fc-4915-a349-e41d87c921ea.mp4
Credits: