Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

neovim autocommands got merged, describe them in guide #100

Open
matu3ba opened this issue Feb 28, 2022 · 4 comments
Open

neovim autocommands got merged, describe them in guide #100

matu3ba opened this issue Feb 28, 2022 · 4 comments

Comments

@matu3ba
Copy link
Contributor

matu3ba commented Feb 28, 2022

neovim/neovim#14661 (lua: autocmds take 2)
see also the not yet merged PR on the docs: https://github.com/neovim/neovim/pull/17545/files

@matu3ba
Copy link
Contributor Author

matu3ba commented Feb 28, 2022

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
Copy link
Contributor Author

matu3ba commented Mar 1, 2022

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

@gegoune
Copy link

gegoune commented Mar 1, 2022

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.

@matu3ba
Copy link
Contributor Author

matu3ba commented Mar 6, 2022

Also works for buffers now: neovim/neovim#17594

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants