From a77c460cf85164cfff4f36dc0b0561f78ef0c328 Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Thu, 9 Nov 2023 13:08:55 -0800 Subject: [PATCH] :wrench: Added gD go to def in new tab --- .config/nvim/lua/neovim/remap.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.config/nvim/lua/neovim/remap.lua b/.config/nvim/lua/neovim/remap.lua index c61dedd7..6ff3dff0 100644 --- a/.config/nvim/lua/neovim/remap.lua +++ b/.config/nvim/lua/neovim/remap.lua @@ -103,6 +103,32 @@ vim.keymap.set("n", "u", ":UndotreeToggle") -- runs npm tests without having to leave vim vim.keymap.set("n", "t", ":w|!npm test") +-- opens go to definition in new tab if not in current file +vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts) + +vim.keymap.set("n", "gD", function() + local org_path = vim.api.nvim_buf_get_name(0) + + -- Go to definition: + vim.api.nvim_command("normal gd") + + -- Wait LSP server response + vim.wait(100, function() end) + + local new_path = vim.api.nvim_buf_get_name(0) + if not (org_path == new_path) then + -- Create a new tab for the original file + vim.api.nvim_command("0tabnew %") + + -- Restore the cursor position + vim.api.nvim_command("b " .. org_path) + vim.api.nvim_command('normal! `"') + + -- Switch to the original tab + vim.api.nvim_command("normal! gt") + end +end, bufopts) + -- dap Keybindings vim.keymap.set("n", "dbp", ":lua require'dap'.toggle_breakpoint()") vim.keymap.set("n", "dco", ":lua require'dap'.continue()")