diff options
Diffstat (limited to 'neovim/.config/nvim/lua/config/autocmds.lua')
| -rw-r--r-- | neovim/.config/nvim/lua/config/autocmds.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/config/autocmds.lua b/neovim/.config/nvim/lua/config/autocmds.lua new file mode 100644 index 0000000..7bc4f6b --- /dev/null +++ b/neovim/.config/nvim/lua/config/autocmds.lua | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | -- Remove trailing spaces on save, preserving cursor and search pattern | ||
| 2 | local function strip_trailing_whitespace() | ||
| 3 | if vim.list_contains({ "markdown", "diff" }, vim.bo.filetype) then | ||
| 4 | return | ||
| 5 | end | ||
| 6 | local view = vim.fn.winsaveview() | ||
| 7 | vim.cmd([[keeppatterns %s/\s\+$//e]]) | ||
| 8 | vim.fn.winrestview(view) | ||
| 9 | end | ||
| 10 | |||
| 11 | vim.api.nvim_create_autocmd("BufWritePre", { | ||
| 12 | pattern = "*", | ||
| 13 | callback = strip_trailing_whitespace, | ||
| 14 | }) | ||
| 15 | |||
| 16 | -- Note: the colorscheme (with its "desert" fallback) is applied from | ||
| 17 | -- lua/plugins/colorscheme.lua's own `config` function, not here — under | ||
| 18 | -- lazy.nvim that's the natural place to react to "the plugin is now loaded". | ||
| 19 | -- | ||
| 20 | -- Note: the vimrc's "reload vimrc on save" autocmd has no clean Lua | ||
| 21 | -- equivalent (module caching means `require()`-based configs aren't simply | ||
| 22 | -- re-sourceable) and is deliberately not ported. | ||
