diff options
Diffstat (limited to 'nvim/lua/core/autocmds.lua')
-rw-r--r-- | nvim/lua/core/autocmds.lua | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/nvim/lua/core/autocmds.lua b/nvim/lua/core/autocmds.lua new file mode 100644 index 0000000..898aeb7 --- /dev/null +++ b/nvim/lua/core/autocmds.lua @@ -0,0 +1,98 @@ +-- Core autocommands
+-- Centralized place for all autocommands
+
+--------------------------------
+-- FILE DETECTION & RELOADING
+--------------------------------
+
+-- Auto-reload files when changed externally
+local file_change_detect = vim.api.nvim_create_augroup("FileChangeDetect", { clear = true })
+vim.api.nvim_create_autocmd({"FocusGained", "BufEnter", "BufWinEnter", "WinEnter", "CursorHold", "CursorHoldI"}, {
+ group = file_change_detect,
+ callback = function()
+ vim.cmd("checktime")
+ end,
+})
+
+vim.api.nvim_create_autocmd("FileChangedShellPost", {
+ group = file_change_detect,
+ callback = function()
+ vim.notify("File changed on disk. Buffer reloaded.", vim.log.levels.WARN)
+ vim.cmd("checktime")
+ end,
+})
+
+--------------------------------
+-- TERMINAL BEHAVIOR
+--------------------------------
+
+-- Terminal settings and keymaps
+local terminal_settings = vim.api.nvim_create_augroup("TerminalSettings", { clear = true })
+vim.api.nvim_create_autocmd({"TermOpen", "BufEnter"}, {
+ group = terminal_settings,
+ callback = function()
+ if vim.opt.buftype:get() == "terminal" then
+ vim.cmd("startinsert")
+
+ -- Terminal keymaps
+ local opts = { noremap = true, silent = true, buffer = true }
+ vim.keymap.set("t", "<C-d>", [[<C-\><C-n><cmd>ToggleTerm<CR>]], opts)
+ vim.keymap.set("t", "<C-q>", [[<C-\><C-n><cmd>ToggleTerm<CR>]], opts)
+ vim.keymap.set("t", "jk", [[<C-\><C-n>]], opts)
+ vim.keymap.set("t", "<C-h>", [[<C-\><C-n><C-W>h]], opts)
+ vim.keymap.set("t", "<C-j>", [[<C-\><C-n><C-W>j]], opts)
+ vim.keymap.set("t", "<C-k>", [[<C-\><C-n><C-W>k]], opts)
+ vim.keymap.set("t", "<C-l>", [[<C-\><C-n><C-W>l]], opts)
+ end
+ end,
+})
+
+--------------------------------
+-- CUSTOM FILETYPES
+--------------------------------
+
+-- Custom filetype detection
+local filetype_group = vim.api.nvim_create_augroup("CustomFileTypes", { clear = true })
+
+-- Set up .seq files to use codev syntax
+vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
+ group = filetype_group,
+ pattern = "*.seq",
+ callback = function()
+ vim.bo.filetype = "seq"
+ vim.bo.syntax = "codev"
+ vim.bo.commentstring = "!%s"
+ end,
+})
+
+-- Set up .lis files to use codelis syntax
+vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
+ group = filetype_group,
+ pattern = "*.lis",
+ callback = function()
+ vim.bo.filetype = "lis"
+ vim.bo.syntax = "codelis"
+ end,
+})
+
+--------------------------------
+-- CUSTOM COMMANDS
+--------------------------------
+
+-- Python docstring helper
+vim.api.nvim_create_user_command("PythonDocstring", function()
+ local docstring = [["""
+
+# Information:
+
+# Arguments:
+
+# Returns:
+
+"""]]
+ -- Insert the docstring at the cursor position
+ local line = vim.api.nvim_win_get_cursor(0)[1]
+ vim.api.nvim_buf_set_lines(0, line-1, line-1, false, vim.split(docstring, "\n"))
+ -- Position cursor at the right spot
+ vim.api.nvim_win_set_cursor(0, {line+1, 0})
+end, {})
|