summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/utils.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-03-15 23:26:50 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-03-15 23:26:50 +0100
commit855f4e4f0f22b35641f13614e46b9ab7f6818188 (patch)
tree9a776e07429c16e1df68f4b04c125c46185eed16 /.config/nvim/lua/utils.lua
parent8577c3b7cba714551d3537f3337ee2490bd20106 (diff)
Migration to lua
Diffstat (limited to '.config/nvim/lua/utils.lua')
-rw-r--r--.config/nvim/lua/utils.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua
new file mode 100644
index 0000000..b5f1413
--- /dev/null
+++ b/.config/nvim/lua/utils.lua
@@ -0,0 +1,31 @@
+local function define_augroups(definitions) -- {{{1
+ -- Create autocommand groups based on the passed definitions
+ --
+ -- The key will be the name of the group, and each definition
+ -- within the group should have:
+ -- 1. Trigger
+ -- 2. Pattern
+ -- 3. Text
+ -- just like how they would normally be defined from Vim itself
+ for group_name, definition in pairs(definitions) do
+ vim.cmd('augroup ' .. group_name)
+ vim.cmd('autocmd!')
+
+ for _, def in pairs(definition) do
+ local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
+ vim.cmd(command)
+ end
+
+ vim.cmd('augroup END')
+ end
+end
+
+define_augroups(
+ {_general_settings = {
+ {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'IncSearch\', timeout = 200})'},
+ {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
+ {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
+ {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
+ },
+ }
+)