From a713d9a7cfd1d28f94e9e504b44e64cadbfae06a Mon Sep 17 00:00:00 2001 From: sadan <117494111+sadan4@users.noreply.github.com> Date: Wed, 19 Mar 2025 18:16:03 -0400 Subject: [PATCH] things configure nvim-tree with binds + opts use signature from noice only add A-L/R arows to go back/forward --- init.lua | 3 +++ lua/keymap.lua | 11 ++++++++--- lua/plugins.lua | 3 --- lua/setupnoice.lua | 8 ++++++++ lua/setupsig.lua | 4 ---- lua/setuptree.lua | 44 +++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index 1c68f68..5f19183 100644 --- a/init.lua +++ b/init.lua @@ -19,3 +19,6 @@ require"plugins" require"setup" require"keymap" end +_G.dbg = function (obj) + vim.notify(vim.inspect(obj)) +end diff --git a/lua/keymap.lua b/lua/keymap.lua index d5f6998..e9f08ac 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -4,6 +4,8 @@ vim.g.mapleader = " " vim.keymap.set("n", "", ""); vim.keymap.set("n", "", ""); +vim.keymap.set("n", "", ""); +vim.keymap.set("n", "", ""); -- is mapped to hover -- unmap vim.keymap.set({"v", "n"}, "J", "") @@ -46,9 +48,7 @@ vim.keymap.set("v", "", function () vim.api.nvim_feedkeys("yp", "x", false) end) -- toggle function signature -vim.keymap.set("i", "", function() - require("lsp_signature").toggle_float_win() -end, {}) +-- Moved to noice -- format and vplit remaps vim.keymap.set({ "n", "i" }, "", vim.cmd.Format, {}) -- vscode fold and unfold @@ -88,6 +88,11 @@ vim.keymap.set("n", "e", function() -- print((":e " .. string.gsub(vim.fn.expand("%"), '(.*/)(.*)', '%1'))); vim.api.nvim_feedkeys((":e " .. string.gsub(vim.fn.expand("%"), "(.*/)(.*)", "%1")), "L", false) end) +-- open command line with the path of current buffer already inserted +vim.keymap.set("n", "r", function() + -- print((":r " .. string.gsub(vim.fn.expand("%"), '(.*/)(.*)', '%1'))); + vim.api.nvim_feedkeys((":r " .. string.gsub(vim.fn.expand("%"), "(.*/)(.*)", "%1")), "L", false) +end) vim.keymap.set("n", "c", ':let @+=@"') -- training vim.keymap.set("n", "", ':echoe "Use h"') diff --git a/lua/plugins.lua b/lua/plugins.lua index 3e23639..a14ee40 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -156,9 +156,6 @@ local plugins = { { "williamboman/mason.nvim", }, - { - "ray-x/lsp_signature.nvim", - }, { "williamboman/mason-lspconfig.nvim", }, diff --git a/lua/setupnoice.lua b/lua/setupnoice.lua index 3cfb517..e631a40 100644 --- a/lua/setupnoice.lua +++ b/lua/setupnoice.lua @@ -117,7 +117,15 @@ require("notify").setup({ on_open = makeCloseMap, on_close = removeCloseMap, }) +vim.api.nvim_create_user_command("Notifications", "Telescope notify", { + force = true, +}) vim.notify = require("notify") +vim.keymap.set({"n", "i"}, "", function() + local api = require("noice.lsp.docs") + local message = api.get("signature") + api.hide(message) +end) require("noice").setup({ cmdline = { enabled = true, -- enables the Noice cmdline UI diff --git a/lua/setupsig.lua b/lua/setupsig.lua index ef99df5..e69de29 100644 --- a/lua/setupsig.lua +++ b/lua/setupsig.lua @@ -1,4 +0,0 @@ -local cfg = { - hint_enable = false, -} -- add your config here -require("lsp_signature").setup(cfg) diff --git a/lua/setuptree.lua b/lua/setuptree.lua index 8221745..c266215 100644 --- a/lua/setuptree.lua +++ b/lua/setuptree.lua @@ -4,18 +4,56 @@ vim.g.loaded_netrwPlugin = 1 -- optionally enable 24-bit colour vim.opt.termguicolors = true - local function myOnAttach(bufnr) local api = require("nvim-tree.api") - + local function opts(desc) - return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } end -- defaults api.config.mappings.default_on_attach(bufnr) vim.keymap.set("n", "", api.tree.close, opts("close tree with ctrl+t")) + vim.keymap.set("n", "H", api.tree.collapse_all, opts("Collapse All")) + vim.keymap.set("n", "h", function() + --- @type Node + local node = api.tree.get_node_under_cursor() + api.node.navigate.parent_close(node) + end, opts("Collapse Parent")) + vim.keymap.set("n", "L", function() + local node = api.tree.get_node_under_cursor() + + if node.nodes ~= nil then + -- expand or collapse folder + api.node.open.edit() + else + -- open file as vsplit + api.node.open.vertical() + end + + -- Finally refocus on tree if it was lost + api.tree.focus() + end, opts("VSplit open")) + vim.keymap.set("n", "l", function() + --- @type Node + local node = api.tree.get_node_under_cursor() + + --- weird types + ---@diagnostic disable-next-line: undefined-field + if node.nodes ~= nil then + api.node.open.edit() + end + end) end +vim.keymap.set("n", "", "NvimTreeFindFile") -- OR setup with some options require("nvim-tree").setup({ on_attach = myOnAttach, + hijack_cursor = true, + sync_root_with_cwd = true, + respect_buf_cwd = true, + renderer = { + indent_markers = { + enable = true, + }, + }, })