nvim-lua-guide icon indicating copy to clipboard operation
nvim-lua-guide copied to clipboard

neovim autocommands got merged, describe them in guide

Open matu3ba opened this issue 3 years ago • 4 comments

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

matu3ba avatar Feb 28 '22 14:02 matu3ba

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]] }) 

matu3ba avatar Feb 28 '22 15:02 matu3ba

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

matu3ba avatar Mar 01 '22 21:03 matu3ba

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.

gegoune avatar Mar 01 '22 22:03 gegoune

Also works for buffers now: https://github.com/neovim/neovim/pull/17594

matu3ba avatar Mar 06 '22 23:03 matu3ba