From 095d08c050d67a441765835e7ef56bc0b224d64a Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 2 Nov 2023 18:29:29 +0100 Subject: [PATCH] feat(autocmds): Split config for autocmds --- lua/user/autocmds/groovy.lua | 28 ++++++++++++++++++++++++++++ lua/user/autocmds/terminal.lua | 6 ++++++ lua/user/autocmds/text.lua | 9 +++++++++ lua/user/init.lua | 11 ++++------- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 lua/user/autocmds/groovy.lua create mode 100644 lua/user/autocmds/terminal.lua create mode 100644 lua/user/autocmds/text.lua diff --git a/lua/user/autocmds/groovy.lua b/lua/user/autocmds/groovy.lua new file mode 100644 index 0000000..1bd5eff --- /dev/null +++ b/lua/user/autocmds/groovy.lua @@ -0,0 +1,28 @@ +vim.api.nvim_create_autocmd( + "FileType", { + desc = "Customizations for groovy files", + -- group = vim.api.nvim_create_augroup("groovy", { clear = true }), + pattern = { "groovy", "Jenkinsfile" }, + callback = function() + local Terminal = require('toggleterm.terminal').Terminal + local groovysh = Terminal:new({ + name = "groovysh", + cmd = "groovysh", + hidden = true, + close_on_exit = true, + }) + + function _groovysh_toggle() + groovysh:toggle() + end + + vim.api.nvim_set_keymap("n", "", "lua _groovysh_toggle()", { noremap = true, silent = true }) + vim.api.nvim_set_keymap("i", "", "lua _groovysh_toggle()", { noremap = true, silent = true }) + + -- vim.api.nvim_set_keymap('n', '', ':terminal groovysh', { noremap = true, silent = true }) + -- vim.opt_local.wrap = true + -- vim.opt_local.spell = true + end, + -- command = "setlocal wrap spell", + } +) diff --git a/lua/user/autocmds/terminal.lua b/lua/user/autocmds/terminal.lua new file mode 100644 index 0000000..a6528d3 --- /dev/null +++ b/lua/user/autocmds/terminal.lua @@ -0,0 +1,6 @@ +vim.api.nvim_create_autocmd("TermOpen", { + desc = "Auto switch to insert mode for terminal", + group = vim.api.nvim_create_augroup("term_auto_insert", { clear = true }), + pattern = "term://*", + command = "startinsert", +}) diff --git a/lua/user/autocmds/text.lua b/lua/user/autocmds/text.lua new file mode 100644 index 0000000..dd20405 --- /dev/null +++ b/lua/user/autocmds/text.lua @@ -0,0 +1,9 @@ +vim.api.nvim_create_autocmd("FileType", { + desc = "Enable wrap and spell for text like documents", + group = vim.api.nvim_create_augroup("auto_spell", { clear = true }), + pattern = { "gitcommit", "markdown", "text", "plaintex" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) diff --git a/lua/user/init.lua b/lua/user/init.lua index f59b672..c8536a8 100644 --- a/lua/user/init.lua +++ b/lua/user/init.lua @@ -14,13 +14,10 @@ return { -- }) -- Set up custom autocmds - vim.api.nvim_create_augroup("myterm", { clear = true }) - vim.api.nvim_create_autocmd("TermOpen", { - desc = "Auto switch to insert mode for terminal", - group = "myterm", - pattern = "term://*", - command = "startinsert", - }) + require "user.autocmds.text" + require "user.autocmds.terminal" + require "user.autocmds.groovy" + -- Set up custom filetypes -- vim.filetype.add { -- extension = {