diff options
Diffstat (limited to 'nvim/.config')
-rw-r--r-- | nvim/.config/nvim/lua/filetree.lua | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/nvim/.config/nvim/lua/filetree.lua b/nvim/.config/nvim/lua/filetree.lua index 761aca6..0760163 100644 --- a/nvim/.config/nvim/lua/filetree.lua +++ b/nvim/.config/nvim/lua/filetree.lua @@ -1,9 +1,10 @@ local tree_cb = require'nvim-tree.config'.nvim_tree_callback + require'nvim-tree'.setup { - open_on_setup = true, hijack_cursor = true, view = { + width = 30, mappings = { list = { { key = "l", cb = tree_cb("edit") }, @@ -15,5 +16,27 @@ require'nvim-tree'.setup { } } +local function open_on_startup(data) + + -- buffer is a [No Name] + local no_name = data.file == "" and vim.bo[data.buf].buftype == "" + + -- buffer is a directory + local directory = vim.fn.isdirectory(data.file) == 1 + + if not no_name and not directory then + return + end + + -- change to the directory + if directory then + vim.cmd.cd(data.file) + end + + -- open the tree + require("nvim-tree.api").tree.open() +end + vim.api.nvim_set_keymap('n', '<F3>', ':NvimTreeToggle<CR>', { noremap = true, silent = true }) vim.api.nvim_command('autocmd BufEnter * ++nested if winnr("$") == 1 && bufname() == "NvimTree_" . tabpagenr() | quit | endif') +vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_on_startup }) |