diff --git a/nvim/init.lua b/nvim/init.lua index 9d6cf7c..8cb5c2f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,4 +1,5 @@ require 'fs.options' require 'fs.plugins' +require 'fs.autocmds' vim.cmd('runtime old.vim') diff --git a/nvim/init.vim b/nvim/init.vim index ac9efcc..1fd665e 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -1,3 +1,2 @@ source ~/.config/nvim/viml/keymaps.vim -source ~/.config/nvim/viml/autocmds.vim diff --git a/nvim/lua/fs/autocmds.lua b/nvim/lua/fs/autocmds.lua new file mode 100644 index 0000000..c90ec23 --- /dev/null +++ b/nvim/lua/fs/autocmds.lua @@ -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()' }, + }, +} +