Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • You could kill the line you're on, call delete-trailing-whitespace then yank the line back. Of course, any whitespace after your cursor would be saved this way too. Alternatively you could find the last non whitespace character of the line you're on, call the two argument form of delete-trailing-whitespace with 0 as the start and that point as the end. Then call d-t-w again, with the cursor's point (or the point of the start of the next line, if you want to save whitespace after the cursor) as the start and the end of the buffer as the end. Commented Apr 24, 2019 at 16:50
  • 3
    You could use ethan-wspace which does not interfer with the cursor position. Commented Apr 25, 2019 at 9:13
  • @AndrewSwann ethan-wspace is exactly what I was looking for. If you make your comment an answer, I will mark it as answered. Commented May 1, 2019 at 15:38
  • 1
    I highly recommend using either ws-butler or ws-trim -- both libraries will prevent you from creating trailing whitespace in a file, while leaving lines which you haven't edited untouched. (Note that in a version controlled environment, this is exactly what you want.) See Version control friendly options (modify only the lines you have edited) Commented May 2, 2019 at 9:02