Open matu3ba opened 2 years ago
For something useful and minimal, you could provide
vim.api.nvim_create_augroup({ name = 'MYAUCMDS', clear = true })
-- text yank highlighting
vim.api.nvim_create_autocmd({ group='MYAUCMDS', event = 'TextYankPost', pattern = '*', command = [[silent! lua require'vim.highlight'.on_yank({timeout = 100})]], })
-- remove trailing spaces
vim.api.nvim_create_autocmd({ group='MYAUCMDS', event = 'BufWritePre', pattern = '*', command = [[:%s/\s\+$//e]] })
With the latest breaking change, this is now
vim.api.nvim_create_augroup('MYAUCMDS', {clear = true})
vim.api.nvim_create_autocmd('TextYankPost', {group = 'MYAUCMDS', pattern = '*', command = [[silent! lua require'vim.highlight'.on_yank({timeout = 100})]]})
vim.api.nvim_create_autocmd('BufWritePre', {group = 'MYAUCMDS', pattern = '*', command = [[:%s/\s\+$//e]]}) -- remove trailing spaces
vim.api.nvim_create_autocmd('TextYankPost', {group = 'MYAUCMDS', pattern = '*', command = [[silent! lua require'vim.highlight'.on_yank({timeout = 100})]]})
This one isn't correct although it works. You can use callback
instead of `command:
vim.api.nvim_create_autocmd('TextYankPost', {group = 'MYAUCMDS', pattern = '*', callback = function() require'vim.highlight'.on_yank({timeout = 100}) end})
or even
vim.api.nvim_create_autocmd('TextYankPost', {group = 'MYAUCMDS', pattern = '*', callback = require'vim.highlight'.on_yank})
if there is no need to pass any arguments.
Also works for buffers now: https://github.com/neovim/neovim/pull/17594
https://github.com/neovim/neovim/pull/14661 (lua: autocmds take 2) see also the not yet merged PR on the docs: https://github.com/neovim/neovim/pull/17545/files