vim: use nvim 0.7 new API for create autocmds in lua

This commit is contained in:
Fernando Schauenburg 2022-07-01 22:30:50 +02:00
parent cedb033443
commit 10466e0391

View file

@ -1,31 +1,36 @@
local function make_autocmds(groups) local augroup = vim.api.nvim_create_augroup
for name, commands in pairs(groups) do local autocmd = vim.api.nvim_create_autocmd
vim.cmd('augroup my_' .. name)
vim.cmd('autocmd!')
for _, item in ipairs(commands) do
vim.cmd('autocmd ' .. table.concat(item, ' '))
end
vim.cmd('augroup END')
end
end
make_autocmds { local id = augroup("my_autocmds", { clear = true} )
buffers = {
-- Make it possible to use `gf` to jump to my configuration modules. autocmd({'BufNewFile', 'BufRead'}, {
{ 'BufNewFile,BufRead', 'init.lua', desc = 'Make it possible to use `gf` to jump to my neovim lua modules.',
"setlocal path+=~/.config/nvim/lua includeexpr=substitute(v:fname,'\\\\.','/','g')"}, group = id,
}, pattern = 'init.lua',
windows = { command = "setlocal path+=~/.config/nvim/lua includeexpr=substitute(v:fname,'\\\\.','/','g')"
-- Disable cursorline when entering Insert mode (but remember it)... })
{ 'InsertEnter', '*',
[[let w:had_cursorline=&cursorline | set nocursorline]] }, autocmd('InsertEnter', {
-- ...and re-enable when leaving if it had been set before. desc = 'Disable `cursorline` when entering Insert mode.',
{ 'InsertLeave', '*', group = id,
[[if exists('w:had_cursorline') | let &cursorline=w:had_cursorline | endif]] }, pattern = '*',
}, callback = function(args)
yank = { vim.w.had_cursorline = vim.opt.cursorline:get()
-- Briefly highlight yanked text. vim.opt.cursorline = false
{ 'TextYankPost', '*', 'silent! lua vim.highlight.on_yank()' }, end
}, })
}
autocmd('InsertLeave', {
desc = 'Enable `cursorline` when leaving Insert mode (if it was set before entering).',
group = id,
pattern = '*',
callback = function(args) vim.opt.cursorline = vim.w.had_cursorline end
})
autocmd('TextYankPost', {
desc = 'Briefly highlight yanked text.',
group = id,
pattern = '*',
callback = function(args) vim.highlight.on_yank() end
})