Skip to content

Commit 5146198

Browse files
authored
feat: add NvimTreeFindFileToggle (#735)
1 parent ec3f10e commit 5146198

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ let g:nvim_tree_icons = {
181181
nnoremap <C-n> :NvimTreeToggle<CR>
182182
nnoremap <leader>r :NvimTreeRefresh<CR>
183183
nnoremap <leader>n :NvimTreeFindFile<CR>
184-
" NvimTreeOpen, NvimTreeClose, NvimTreeFocus and NvimTreeResize are also available if you need them
184+
" NvimTreeOpen, NvimTreeClose, NvimTreeFocus, NvimTreeFindFileToggle, and NvimTreeResize are also available if you need them
185185
186186
set termguicolors " this variable must be enabled for colors to be applied properly
187187

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ It will also open the leafs of the tree leading to the file in the buffer
4949
(if you opened a file with something else than the NvimTree, like `fzf` or
5050
`:split`)
5151

52+
|:NvimTreeFindFileToggle| *:NvimTreeFindFileToggle*
53+
54+
close the tree or change the cursor in the tree for the current bufname,
55+
similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile|
56+
5257
|:NvimTreeClipboard| *:NvimTreeClipboard*
5358

5459
Print clipboard content for both cut and copy

lua/nvim-tree.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ function M.focus()
2424
view.focus();
2525
end
2626

27-
function M.toggle()
27+
function M.toggle(find_file)
2828
if view.win_open() then
2929
view.close()
3030
else
31-
if _config.update_focused_file.enable then
31+
if _config.update_focused_file.enable or find_file then
3232
M.find_file(true)
3333
end
3434
if not view.win_open() then
@@ -356,11 +356,12 @@ local function setup_vim_commands()
356356
vim.cmd [[
357357
command! NvimTreeOpen lua require'nvim-tree'.open()
358358
command! NvimTreeClose lua require'nvim-tree'.close()
359-
command! NvimTreeToggle lua require'nvim-tree'.toggle()
359+
command! NvimTreeToggle lua require'nvim-tree'.toggle(false)
360360
command! NvimTreeFocus lua require'nvim-tree'.focus()
361361
command! NvimTreeRefresh lua require'nvim-tree'.refresh()
362362
command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
363363
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
364+
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
364365
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize(<args>)
365366
]]
366367
end

0 commit comments

Comments
 (0)