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.
Post History
Problem I would like to trim trailing whitespace on save in all files except .diffs using Neovim. Have vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*" }, command = [[%s/\s...
#4: Post edited
How to trim trailing whitespace in all files except diffs
- How to trim trailing whitespace in all files except diffs in Neovim
#3: Post edited
- # Problem
I would like to trim trailing whitespace on all files except `.diff`s.- # Have
- ```lua
- 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:
- ```lua
- 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](https://neovim.io/doc/user/api.html#_autocmd-functions) and does not
- mention use of double brackets (`[[`) in the command.
- Improvements to the overall approach welcome.
- # Problem
- I would like to trim trailing whitespace on save in all files except `.diff`s using Neovim.
- # Have
- ```lua
- 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:
- ```lua
- 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](https://neovim.io/doc/user/api.html#_autocmd-functions) and does not
- mention use of double brackets (`[[`) in the command.
- Improvements to the overall approach welcome.
#1: Initial revision
How to trim trailing whitespace in all files except diffs
# Problem I would like to trim trailing whitespace on all files except `.diff`s. # Have ```lua 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: ```lua 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](https://neovim.io/doc/user/api.html#_autocmd-functions) and does not mention use of double brackets (`[[`) in the command. Improvements to the overall approach welcome.