diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-05 14:27:52 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-05 14:27:52 +0300 |
commit | 53c8eb3ef1f44206bcbcde2f5e2820f68b627307 (patch) | |
tree | 26dc2c4a91a2e381c2559192d6348224893c1824 | |
parent | 4727c066b8849f27d6aff56cb272f38f3fb6cb70 (diff) | |
download | dotfiles-53c8eb3ef1f44206bcbcde2f5e2820f68b627307.tar.gz |
feat(nvim): custom open_on_startup callback
-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 }) |