From b8cd8910f3d64759567da87b2e66df8fc9ed6ab6 Mon Sep 17 00:00:00 2001 From: spinach Date: Sun, 23 Nov 2025 22:18:52 -0500 Subject: [PATCH] fixed deps and added autocmds for empty buffers --- lua/config/keymap.lua | 4 --- lua/plugins/filetree.lua | 56 ++++++++++++++++++++++++++++++++++++-- lua/plugins/treesitter.lua | 37 +++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 lua/plugins/treesitter.lua diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua index 875feb1..ca6ff74 100644 --- a/lua/config/keymap.lua +++ b/lua/config/keymap.lua @@ -16,10 +16,6 @@ end vim.keymap.set("n", "b", ":lua ToggleTransparent()") --- nvim-tree bindings - -vim.keymap.set("n", "t", ":NvimTreeToggle") - -- simple spell check toggle local function SpellToggle() if vim.o.spell == nil or vim.o.spell then diff --git a/lua/plugins/filetree.lua b/lua/plugins/filetree.lua index 0d07d72..5a90d84 100644 --- a/lua/plugins/filetree.lua +++ b/lua/plugins/filetree.lua @@ -2,22 +2,72 @@ return { { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", - depends = { + dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", }, + keys = { + { + "t", + function() + require("neo-tree.command").execute({ + toggle = true, + source = "filesystem", + position = "left", + }) + end, + desc = "Buffers (root dir)", + }, + }, + config = function() + -- automatically close file tree if file is selected + require("neo-tree").setup({ + close_if_last_window = true, + event_handlers = { + { + event = "file_open_requested", + handler = function() + require("neo-tree.command").execute({ action = "close" }) + end, + }, + -- makes it so quitting inside buffer quits all buffers + { + event = "neo_tree_buffer_enter", + handler = function() + vim.cmd("cabbrev q qall") + end, + }, + }, + }) + + -- auto open file tree on empty buffer or directory + vim.api.nvim_create_autocmd("VimEnter", { + callback = function(data) + local is_directory = vim.fn.isdirectory(data.file) == 1 + local no_name = data.file == "" and vim.bo[data.buf].buftype == "" + + if is_directory or no_name then + require("neo-tree.command").execute({ + action = "focus", + source = "filesystem", + position = "left", + }) + end + end, + }) + end, lazy = false, -- neo-tree lazy loads itself }, { "nvim-telescope/telescope.nvim", branch = "0.1.x", event = "VimEnter", - depends = { "nvim-lua/plenary.nvim"}, + dependencies = { "nvim-lua/plenary.nvim"}, opts = { defaults = { layout_config = { - horizontal = { width = 0.8 } + horizontal = { width = 0.9 } }, }, }, diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..c64eb27 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,37 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + }, + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + "lua", + "vim", + "vimdoc", + "javascript", + "typescript", + "python", + "go", + -- add other languages you need + }, + highlight = { + enable = true, + }, + indent = { + enable = true, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + }, + }, + }) + end, +}