diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 5a8501b..2b59674 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -74,7 +74,44 @@ autocmd({ "BufEnter" }, { end, }) --- Set up autocommands and highlight settings +-- ━━━━━━━━━━━━━━━━━━━━━━━ Set up Qalc keymappings ━━━━━━━━━━━━━━━━━━━━━━━ +-- Create a group for filetype-specific mappings +vim.api.nvim_create_augroup("QalcFileTypeMappings", { clear = true }) + +-- Create an autocommand for the qalc filetype +vim.api.nvim_create_autocmd("FileType", { + pattern = "qalc", + group = "QalcFileTypeMappings", + callback = function() + -- Set the key mapping: 'y' to run the :QalcYank command in normal mode + vim.keymap.set( -- Yank Result + "n", + "y", + ":QalcYank +", + { noremap = true, silent = true } + ) + -- Set the key mapping: 'q' to run the :QalcClose command in normal mode + vim.keymap.set( -- Close Qalc + "n", + "q", + ":QalcClose", + { noremap = true, silent = true } + ) + end, +}) + +-- Define a custom command to close the Qalc buffer +vim.api.nvim_create_user_command("QalcClose", function() + local buf_name = vim.api.nvim_buf_get_name(0) + if buf_name ~= "" then + vim.cmd("bd!") + else + -- If the buffer has no name, just remove it without invoking :bd! + vim.api.nvim_buf_delete(0, { force = true }) + end +end, { bang = true }) + +-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ Set up highlights ━━━━━━━━━━━━━━━━━━━━━━━━━━ local load_highlight = require("utils.highlight") load_highlight.setup_autocommands() load_highlight.setup_dashboard_highlight()