this post was submitted on 15 Oct 2025
1 points (100.0% liked)

ShareGPT

88 readers
1 users here now

To share LLM text output that others might find interesting.

founded 2 years ago
MODERATORS
 

If you want to remove all trailing whitespace in a file in Neovim, use this command:

:%s/\s\+$//e

Explanation:

  • :%s → substitute across the entire file
  • \s\+$ → matches one or more spaces or tabs at the end of a line
  • //e → suppress errors if no match is found

Optional: Automatically remove trailing whitespace on save:

Vimscript version (init.vim):

autocmd BufWritePre * :%s/\s\+$//e

Lua version (init.lua):

vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = "*",
  command = [[%s/\s\+$//e]],
})

This ensures your files are always clean of trailing spaces.

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here