diff options
author | Subho Banerjee <[email protected]> | 2021-10-16 05:03:17 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-16 12:03:17 +0200 |
commit | 281c54ba55651af0b33dadeb3419e19b10fbed45 (patch) | |
tree | 91ac4dc26af395ed40fd64c181b97f06394d9848 | |
parent | ef41a3d24e753b7e82fe31ebe9e74048881c13e8 (diff) |
[Bugfix]: Allow user autocmds (#1776)
Co-authored-by: kylo252 <[email protected]>
-rw-r--r-- | lua/lvim/config/init.lua | 3 | ||||
-rw-r--r-- | lua/lvim/core/autocmds.lua | 155 |
2 files changed, 60 insertions, 98 deletions
diff --git a/lua/lvim/config/init.lua b/lua/lvim/config/init.lua index e14f96fa..c06d28ef 100644 --- a/lua/lvim/config/init.lua +++ b/lua/lvim/config/init.lua @@ -27,6 +27,9 @@ function M:init() local settings = require "lvim.config.settings" settings.load_options() + local autocmds = require "lvim.core.autocmds" + lvim.autocommands = autocmds.load_augroups() + local lvim_lsp_config = require "lvim.lsp.config" lvim.lsp = vim.deepcopy(lvim_lsp_config) diff --git a/lua/lvim/core/autocmds.lua b/lua/lvim/core/autocmds.lua index 4f29f0e1..5d1d365e 100644 --- a/lua/lvim/core/autocmds.lua +++ b/lua/lvim/core/autocmds.lua @@ -1,110 +1,69 @@ -local autocommands = {} -local user_config_file = require("lvim.config"):get_user_config_path() +local M = {} -lvim.autocommands = { - _general_settings = { - { - "Filetype", - "*", - "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))", - }, - { - "FileType", - "qf", - "nnoremap <silent> <buffer> q :q<CR>", +--- Load the default set of autogroups and autocommands. +function M.load_augroups() + local user_config_file = vim.fn.resolve(require("lvim.config"):get_user_config_path()) + + return { + _general_settings = { + { + "Filetype", + "*", + "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))", + }, + { "FileType", "qf,help,man", "nnoremap <silent> <buffer> q :close<CR>" }, + { + "TextYankPost", + "*", + "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", + }, + { + "BufWinEnter", + "dashboard", + "setlocal cursorline signcolumn=yes cursorcolumn number", + }, + { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" }, + { "FileType", "qf", "set nobuflisted" }, + -- { "VimLeavePre", "*", "set title set titleold=" }, }, - { - "FileType", - "lsp-installer", - "nnoremap <silent> <buffer> q :q<CR>", + _formatoptions = { + { + "BufWinEnter,BufRead,BufNewFile", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, }, - { - "TextYankPost", - "*", - "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", + _filetypechanges = { + { "BufWinEnter", ".tf", "setlocal filetype=terraform" }, + { "BufRead", "*.tf", "setlocal filetype=terraform" }, + { "BufNewFile", "*.tf", "setlocal filetype=terraform" }, + { "BufWinEnter", ".zsh", "setlocal filetype=sh" }, + { "BufRead", "*.zsh", "setlocal filetype=sh" }, + { "BufNewFile", "*.zsh", "setlocal filetype=sh" }, }, - { - "BufWinEnter", - "*", - "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + _git = { + { "FileType", "gitcommit", "setlocal wrap" }, + { "FileType", "gitcommit", "setlocal spell" }, }, - { - "BufWinEnter", - "dashboard", - "setlocal cursorline signcolumn=yes cursorcolumn number", + _markdown = { + { "FileType", "markdown", "setlocal wrap" }, + { "FileType", "markdown", "setlocal spell" }, }, - { - "BufRead", - "*", - "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + _buffer_bindings = { + { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" }, }, - { - "BufNewFile", - "*", - "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + _auto_resize = { + -- will cause split windows to be resized evenly if main window is resized + { "VimResized", "*", "tabdo wincmd =" }, }, - { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" }, - { - "FileType", - "qf", - "set nobuflisted", + _general_lsp = { + { "FileType", "lspinfo,lsp-installer,null-ls-info", "nnoremap <silent> <buffer> q :close<CR>" }, }, - -- { "VimLeavePre", "*", "set title set titleold=" }, - }, - _filetypechanges = { - { "BufWinEnter", ".tf", "setlocal filetype=terraform" }, - { "BufRead", "*.tf", "setlocal filetype=terraform" }, - { "BufNewFile", "*.tf", "setlocal filetype=terraform" }, - { "BufWinEnter", ".zsh", "setlocal filetype=sh" }, - { "BufRead", "*.zsh", "setlocal filetype=sh" }, - { "BufNewFile", "*.zsh", "setlocal filetype=sh" }, - }, - -- _solidity = { - -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'}, - -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'} - -- }, - -- _gemini = { - -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'}, - -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'} - -- }, - _git = { - { "FileType", "gitcommit", "setlocal wrap" }, - { "FileType", "gitcommit", "setlocal spell" }, - }, - _markdown = { - { "FileType", "markdown", "setlocal wrap" }, - { "FileType", "markdown", "setlocal spell" }, - }, - _buffer_bindings = { - { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" }, - }, - _auto_resize = { - -- will cause split windows to be resized evenly if main window is resized - { "VimResized", "*", "wincmd =" }, - }, - _packer_compile = { - -- will run PackerCompile after writing plugins.lua - { "BufWritePost", "plugins.lua", "PackerCompile" }, - }, - _general_lsp = { - { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" }, - }, - - -- _fterm_lazygit = { - -- -- will cause esc key to exit lazy git - -- {"TermEnter", "*", "call LazyGitNativation()"} - -- }, - -- _mode_switching = { - -- -- will switch between absolute and relative line numbers depending on mode - -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'}, - -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'}, - -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'}, - -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'}, - -- }, - custom_groups = {}, -} + custom_groups = {}, + } +end -function autocommands.define_augroups(definitions) -- {{{1 +function M.define_augroups(definitions) -- {{{1 -- Create autocommand groups based on the passed definitions -- -- The key will be the name of the group, and each definition @@ -126,4 +85,4 @@ function autocommands.define_augroups(definitions) -- {{{1 end end -return autocommands +return M |