commit 545cb918ea60c967420c08c9315c13f104aced6d
parent 12d685507526a55343f15a57a5b010a718944f53
Author: mehdi-norouzi <mehdeenoroozi@gmail.com>
Date: Sun, 8 Sep 2024 13:06:40 +0330
nvim: add keymap for compilation mode
Diffstat:
1 file changed, 19 insertions(+), 0 deletions(-)
diff --git a/nvim/.config/nvim/lua/mehdi/mappings.lua b/nvim/.config/nvim/lua/mehdi/mappings.lua
@@ -8,3 +8,22 @@ vim.keymap.set("n", "-", "<cmd>Oil<CR>")
-- print the date in current buffer
vim.keymap.set("n", "<leader>n", "Go<Esc>:r!date<cr>0i## <Esc>o"--[[ :r!echo $(date)<cr>0i## <Esc>o" ]], opts)
+
+-- Focus on a window by its name
+function FocusWindowByName(name)
+ vim.cmd("Recompile");
+ for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
+ local buf = vim.api.nvim_win_get_buf(win)
+ local bufname = vim.api.nvim_buf_get_name(buf)
+ if bufname:match(name) then
+ vim.api.nvim_set_current_win(win)
+ return
+ end
+ end
+ print("No window found with name: " .. name)
+end
+
+-- Run :Recompile and focus on the "compilation" pane
+vim.cmd('command! RecompileAndFocus lua FocusWindowByName("compilation")')
+vim.keymap.set('n', '<leader>c', ':RecompileAndFocus<CR>', { noremap = true, silent = true })
+