vim: port autocmd to lua using wrapper function

Wrapper is needed until this PR is merged into neovim:

    https://github.com/neovim/neovim/pull/14661
This commit is contained in:
Fernando Schauenburg 2021-11-11 09:43:17 +01:00
parent e3c0dac924
commit d9ae564153
3 changed files with 37 additions and 1 deletions

View file

@ -1,4 +1,5 @@
require 'fs.options' require 'fs.options'
require 'fs.plugins' require 'fs.plugins'
require 'fs.autocmds'
vim.cmd('runtime old.vim') vim.cmd('runtime old.vim')

View file

@ -1,3 +1,2 @@
source ~/.config/nvim/viml/keymaps.vim source ~/.config/nvim/viml/keymaps.vim
source ~/.config/nvim/viml/autocmds.vim

36
nvim/lua/fs/autocmds.lua Normal file
View file

@ -0,0 +1,36 @@
local function make_autocmds(groups)
for name, commands in pairs(groups) do
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 {
buffers = {
{ 'BufNewFile,BufRead', 'bash_profile,bashrc,profile', 'set filetype=sh' },
{ 'BufNewFile,BufRead', 'gitconfig', 'set filetype=gitconfig' },
{ 'BufNewFile,BufRead', '*.sx,*.s19', 'set filetype=srec' },
{ 'BufNewFile,BufRead', 'Vagrantfile', 'set filetype=ruby' },
},
filetypes = {
{ 'FileType', 'gitcommit', 'setlocal textwidth=72' },
{ 'FileType', 'gitcommit,markdown,text', 'setlocal formatoptions+=t spell' },
{ 'FileType', 'python', 'setlocal foldmethod=indent foldignore=' },
{ 'FileType', 'vim', 'set foldmethod=marker' },
},
windows = {
-- Disable cursorline when entering Insert mode (but remember it)...
{ 'InsertEnter', '*', 'let g:stored_cursorline=&cursorline | set nocursorline' },
-- ...and re-enable when leaving if it had been set before.
{ 'InsertLeave', '*', 'let &cursorline=g:stored_cursorline' },
},
yank = {
-- Briefly highlight yanked text.
{ 'TextYankPost', '*', 'silent! lua vim.highlight.on_yank()' },
},
}