diff --git a/README.md b/README.md index 8d68987d..e776b504 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ let g:nvim_tree_icons = { nnoremap :NvimTreeToggle nnoremap r :NvimTreeRefresh nnoremap n :NvimTreeFindFile -" NvimTreeOpen, NvimTreeClose, NvimTreeFocus and NvimTreeResize are also available if you need them +" NvimTreeOpen, NvimTreeClose, NvimTreeFocus, NvimTreeFindFileToggle, and NvimTreeResize are also available if you need them set termguicolors " this variable must be enabled for colors to be applied properly diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5bdf0aef..9968f5c9 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -49,6 +49,11 @@ It will also open the leafs of the tree leading to the file in the buffer (if you opened a file with something else than the NvimTree, like `fzf` or `:split`) +|:NvimTreeFindFileToggle| *:NvimTreeFindFileToggle* + +close the tree or change the cursor in the tree for the current bufname, +similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile| + |:NvimTreeClipboard| *:NvimTreeClipboard* Print clipboard content for both cut and copy diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 6b5b195c..e9c0894b 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -24,11 +24,11 @@ function M.focus() view.focus(); end -function M.toggle() +function M.toggle(find_file) if view.win_open() then view.close() else - if _config.update_focused_file.enable then + if _config.update_focused_file.enable or find_file then M.find_file(true) end if not view.win_open() then @@ -356,11 +356,12 @@ local function setup_vim_commands() vim.cmd [[ command! NvimTreeOpen lua require'nvim-tree'.open() command! NvimTreeClose lua require'nvim-tree'.close() - command! NvimTreeToggle lua require'nvim-tree'.toggle() + command! NvimTreeToggle lua require'nvim-tree'.toggle(false) command! NvimTreeFocus lua require'nvim-tree'.focus() command! NvimTreeRefresh lua require'nvim-tree'.refresh() command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard() command! NvimTreeFindFile lua require'nvim-tree'.find_file(true) + command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true) command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize() ]] end