From 431b1bf351e998e9fa1e86574817a3b32d96ae34 Mon Sep 17 00:00:00 2001 From: PeteChu Date: Mon, 3 Apr 2023 23:14:15 +0700 Subject: [PATCH] * feat(harpoon.lua): add keymaps for navigating between files and toggling quick menu * feat(keymaps.lua): add keymap for deleting all buffers except current * feat(nvim-tree.lua): add autocmd to go to last used hidden buffer when deleting a buffer * chore(init.lua): add ThePrimeagen/harpoon plugin to the list of plugins * chore(nvim-tree.lua): add missing comma in filters table * feat(surround.lua): add kylechui/nvim-surround plugin configuration --- after/plugin/harpoon.lua | 8 ++++++++ after/plugin/keymaps.lua | 7 +++++-- after/plugin/nvim-tree.lua | 20 ++++++++++++++++++++ lua/custom/plugins/init.lua | 1 + lua/custom/plugins/nvim-tree.lua | 4 ++-- lua/custom/plugins/surround.lua | 10 ++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 after/plugin/harpoon.lua create mode 100644 lua/custom/plugins/surround.lua diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua new file mode 100644 index 00000000..204b04a9 --- /dev/null +++ b/after/plugin/harpoon.lua @@ -0,0 +1,8 @@ +local mark = require("harpoon.mark") +local ui = require("harpoon.ui") + +vim.keymap.set("n", "ha", mark.add_file) +vim.keymap.set("n", "", ui.toggle_quick_menu) + +vim.keymap.set("n", "hn", function() ui.nav_next() end) +vim.keymap.set("n", "hp", function() ui.nav_prev() end) diff --git a/after/plugin/keymaps.lua b/after/plugin/keymaps.lua index a73d29a4..a8afef7f 100644 --- a/after/plugin/keymaps.lua +++ b/after/plugin/keymaps.lua @@ -62,5 +62,8 @@ keymap("n", "x", "!chmod +x %", { silent = true, desc = "Make [ keymap("n", "Q", "") -- Bufdelete.vim -keymap("n", "bd", ":Bdelete", {desc = "[B]uffer [D]elete"}) -keymap("n", "bw", ":Bwipeout", {desc = "[B]uffer [W]ipeout"}) \ No newline at end of file +keymap("n", "bd", ":Bdelete", { desc = "[B]uffer [D]elete" }) +keymap("n", "bw", ":Bwipeout", { desc = "[B]uffer [W]ipeout" }) + +-- Delete buffer except current +keymap("n", "be", ":%bd|e#|bd#", { silent = true, desc = "[B]uffer Delete [E]xcept" }) diff --git a/after/plugin/nvim-tree.lua b/after/plugin/nvim-tree.lua index bdbfd8d9..7e0ef1be 100644 --- a/after/plugin/nvim-tree.lua +++ b/after/plugin/nvim-tree.lua @@ -21,3 +21,23 @@ end vim.api.nvim_create_autocmd({"QuitPre"}, { callback = function() vim.cmd("NvimTreeClose") end, }) + +-- Go to last used hidden buffer when deleting a buffer +vim.api.nvim_create_autocmd("BufEnter", { + nested = true, + callback = function() + -- Only 1 window with nvim-tree left: we probably closed a file buffer + if #vim.api.nvim_list_wins() == 1 and require("nvim-tree.utils").is_nvim_tree_buf() then + local api = require('nvim-tree.api') + -- Required to let the close event complete. An error is thrown without this. + vim.defer_fn(function() + -- close nvim-tree: will go to the last hidden buffer used before closing + api.tree.toggle({find_file = true, focus = true}) + -- re-open nivm-tree + api.tree.toggle({find_file = true, focus = true}) + -- nvim-tree is still the active window. Go to the previous window. + vim.cmd("wincmd p") + end, 0) + end + end +}) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index b2818a3d..c433512f 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -6,4 +6,5 @@ return { 'fatih/vim-go', 'mbbill/undotree', 'famiu/bufdelete.nvim', + 'ThePrimeagen/harpoon' } diff --git a/lua/custom/plugins/nvim-tree.lua b/lua/custom/plugins/nvim-tree.lua index 5b7c4668..6b044a45 100644 --- a/lua/custom/plugins/nvim-tree.lua +++ b/lua/custom/plugins/nvim-tree.lua @@ -7,8 +7,8 @@ return { }, config = function() require("nvim-tree").setup { - filters = { custom = { "^.git$" } } + filters = { custom = { "^.git$" } }, } end, } -} \ No newline at end of file +} diff --git a/lua/custom/plugins/surround.lua b/lua/custom/plugins/surround.lua new file mode 100644 index 00000000..241ec2c7 --- /dev/null +++ b/lua/custom/plugins/surround.lua @@ -0,0 +1,10 @@ +return { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end +} \ No newline at end of file