Skip to content

Commit 3678169

Browse files
committed
add config to open or close automatically
1 parent 03168a5 commit 3678169

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Plug 'kyazdani42/nvim-tree.lua'
1818
let g:lua_tree_side = 'right' | 'left' "left by default
1919
let g:lua_tree_size = 40 "30 by default
2020
let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default, not working on mac atm
21+
let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
22+
let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
2123
let g:lua_tree_follow = 1 "0 by default, this option will bind BufEnter to the LuaTreeFindFile command
2224
" :help LuaTreeFindFile for more info
2325
@@ -62,6 +64,7 @@ nnoremap <leader>n :LuaTreeFindFile<CR>
6264
- Tree creation should be async
6365
- refactor all `system` call to `libuv` functions, with better error management
6466
- bufferize leafs of node being closed so when opening again the node, we open every directory that was previously open
67+
- make config module to make it easier to add/modify user options
6568

6669
### Features
6770
- sneak like cd command to find a file/directory

doc/nvim-tree-lua.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ Each pattern is passed into the 'ls' function as `--ignore=PATTERN`
5757
|g:lua_tree_follow| *g:lua_tree_follow*
5858

5959
Can be `0` or `1`. When `1`, will bind |:LuaTreeFindFile| to |BufEnter|
60+
Default is 0
6061

62+
|g:lua_tree_auto_open| *g:lua_tree_auto_open*
63+
64+
Can be `0` or `1`. When `1`, will bind |VimEnter| to automatically
65+
open tree on startup if no files are specified.
66+
Default is 0
67+
68+
|g:lua_tree_auto_close| *g:lua_tree_auto_close*
69+
70+
Can be `0` or `1`. When `1`, will bind |BufEnter| to automatically
71+
close the tree if it's the last window.
72+
Default is 0
6173

6274
==============================================================================
6375
INFORMATIONS *nvim-tree-info*

doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
:LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile*
22
:LuaTreeRefresh nvim-tree-lua.txt /*:LuaTreeRefresh*
33
:LuaTreeToggle nvim-tree-lua.txt /*:LuaTreeToggle*
4+
g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open*
5+
g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open*
46
g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow*
57
g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore*
68
g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side*

lua/tree.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ init_tree()
3737

3838
local function toggle()
3939
if is_win_open() == true then
40-
close()
40+
local wins = api.nvim_list_wins()
41+
if #wins > 1 then close() end
4142
else
4243
open()
4344
update_view()

plugin/tree.vim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ let g:loaded_netrwPlugin = 1
99
hi def link LuaTreePopup Normal
1010

1111
au BufWritePost * lua require'tree'.refresh()
12-
au BufEnter * lua require'tree'.check_windows_and_close()
13-
au VimEnter * lua require'tree'.check_buffer_and_open()
12+
13+
if get(g:, 'lua_tree_auto_close') != 0
14+
au BufEnter * lua require'tree'.check_windows_and_close()
15+
endif
16+
17+
if get(g:, 'lua_tree_auto_open') != 0
18+
au VimEnter * lua require'tree'.check_buffer_and_open()
19+
endif
1420

1521
" TODO set status line dynamically on bufenter in the luatree
1622
" to remove lightline and other possible components

0 commit comments

Comments
 (0)