Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
How to trim trailing whitespace in all files except diffs in Neovim
Problem
I would like to trim trailing whitespace on save in all files except .diff
s using Neovim.
Have
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = { "*" },
command = [[%s/\s\+$//e]],
})
Source: https://vi.stackexchange.com/a/37427
Want
Something succinct like this would be great and easy to modify:
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = { "*", "^(*.diff)" },
command = [[%s/\s\+$//e]],
})
Notes
I'm not sure if what I have is the most correct form to begin with. Searching
h:nvim_create_autocmd()
in the neovim docs takes me to Autocmd
Functions and does not
mention use of double brackets ([[
) in the command.
Improvements to the overall approach welcome.
0 comment threads