Skip to content

Commit a864b80

Browse files
authored
chore: refacto setup part 1 (#603)
* chore: refacto setup part 1 refacto setup for code entrypoint following options switched boolean values as options to the setup function: - `nvim_tree_disable_netrw` -> `disable_netrw` - `nvim_tree_hijack_netrw` -> `hijack_netrw` - `nvim_tree_auto_open` -> `open_on_setup` - `nvim_tree_auto_close` -> `auto_close` - `nvim_tree_tab_open` -> `tab_open` - `nvim-tree-update-cwd` -> `update_cwd` - `nvim_tree_hijack_cursor` -> `hijack_cursor` - `nvim_tree_system_open_command` -> `system_open.cmd` - `nvim_tree_system_open_command_args` -> `system_open.args` - `nvim_tree_follow` -> `update_focused_file.enable` - `nvim_tree_follow_update_path` -> `update_focused_file.update_cwd` Also added new option `update_focused_file.ignore_list` which will ignore filepath or filetypes that matches one entry of the list when updating the path if update_cwd is true. * add deprecation warning * update readme * schedule on enter to avoid running before vim first buffer has loaded * update docs * correct typo * rename tab open -> open on tab
1 parent 6780550 commit a864b80

File tree

5 files changed

+329
-196
lines changed

5 files changed

+329
-196
lines changed

README.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,75 @@ Install with [packer](https://github.com/wbthomason/packer.nvim):
2121
```lua
2222
use {
2323
'kyazdani42/nvim-tree.lua',
24-
requires = 'kyazdani42/nvim-web-devicons'
24+
requires = 'kyazdani42/nvim-web-devicons',
25+
config = function() require'nvim-tree'.setup {} end
2526
}
2627
```
2728

2829
## Setup
2930

31+
Options are currently being migrated into the setup function, you need to run `require'nvim-tree'.setup()` in your personal configurations.
32+
Setup should be run in a lua file or in a lua heredoc (`:help lua-heredoc`) if using in a vim file.
33+
Note that options under the `g:` command should be set **BEFORE** running the setup function.
34+
35+
```lua
36+
-- following options are the default
37+
require'nvim-tree'.setup {
38+
-- disables netrw completely
39+
disable_netrw = true,
40+
-- hijack netrw window on startup
41+
hijack_netrw = true,
42+
-- open the tree when running this setup function
43+
open_on_setup = false,
44+
-- will not open on setup if the filetype is in this list
45+
ignore_ft_on_setup = {},
46+
-- closes neovim automatically when the tree is the last **WINDOW** in the view
47+
auto_close = false,
48+
-- opens the tree when changing/opening a new tab if the tree wasn't previously opened
49+
open_on_tab = false,
50+
-- hijack the cursor in the tree to put it at the start of the filename
51+
hijack_cursor = false,
52+
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
53+
update_cwd = false,
54+
-- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
55+
update_focused_file = {
56+
-- enables the feature
57+
enable = false,
58+
-- update the root directory of the tree to the one of the folder containing the file if the file is not under the current root directory
59+
-- only relevant when `update_focused_file.enable` is true
60+
update_cwd = false,
61+
-- list of buffer names / filetypes that will not update the cwd if the file isn't found under the current root directory
62+
-- only relevant when `update_focused_file.update_cwd` is true and `update_focused_file.enable` is true
63+
ignore_list = {}
64+
},
65+
-- configuration options for the system open command (`s` in the tree by default)
66+
system_open = {
67+
-- the command to run this, leaving nil should work in most cases
68+
cmd = nil,
69+
-- the command arguments as a list
70+
args = {}
71+
},
72+
}
73+
```
74+
3075
```vim
3176
let g:nvim_tree_side = 'right' "left by default
3277
let g:nvim_tree_width = 40 "30 by default, can be width_in_columns or 'width_in_percent%'
3378
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
3479
let g:nvim_tree_gitignore = 1 "0 by default
35-
let g:nvim_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
36-
let g:nvim_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
37-
let g:nvim_tree_auto_ignore_ft = [ 'startify', 'dashboard' ] "empty by default, don't auto open tree on specific filetypes.
3880
let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
39-
let g:nvim_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
40-
let g:nvim_tree_follow_update_path = 1 "0 by default, will update the path of the current dir if the file is not inside the tree.
4181
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
4282
let g:nvim_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.`
4383
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
4484
let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and file icon highlight for opened files/directories.
4585
let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
46-
let g:nvim_tree_tab_open = 1 "0 by default, will open the tree when entering a new tab and the tree was previously open
4786
let g:nvim_tree_auto_resize = 0 "1 by default, will resize the tree to its saved width when opening a file
48-
let g:nvim_tree_disable_netrw = 0 "1 by default, disables netrw
49-
let g:nvim_tree_hijack_netrw = 0 "1 by default, prevents netrw from automatically opening when opening directories (but lets you keep its other utilities)
5087
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
5188
let g:nvim_tree_group_empty = 1 " 0 by default, compact folders that only contain a single folder into one node in the file tree
5289
let g:nvim_tree_lsp_diagnostics = 1 "0 by default, will show lsp diagnostics in the signcolumn. See :help nvim_tree_lsp_diagnostics
5390
let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker.
54-
let g:nvim_tree_hijack_cursor = 0 "1 by default, when moving cursor in the tree, will position the cursor at the start of the file on the current line
5591
let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
5692
let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target.
57-
let g:nvim_tree_update_cwd = 1 "0 by default, will update the tree cwd when changing nvim's directory (DirChanged event). Behaves strangely with autochdir set.
5893
let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
5994
let g:nvim_tree_refresh_wait = 500 "1000 by default, control how often the tree can be refreshed, 1000 means the tree can be refresh once per 1000ms.
6095
let g:nvim_tree_window_picker_exclude = {
@@ -148,7 +183,7 @@ highlight NvimTreeFolderIcon guibg=blue
148183
- type `]c` to go to next git item
149184
- type `[c` to go to prev git item
150185
- type `-` to navigate up to the parent directory of the current file/directory
151-
- type `s` to open a file with default system application or a folder with default file manager (if you want to change the command used to do it see `:h g:nvim_tree_system_open_command` and `:h g:nvim_tree_system_open_command_args`)
186+
- type `s` to open a file with default system application or a folder with default file manager (if you want to change the command used to do it see `:h nvim-tree.setup` under `system_open`)
152187
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
153188
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
154189
- `<C-v>` will open the file in a vertical split

doc/nvim-tree-lua.txt

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,107 @@ Print clipboard content for both cut and copy
5858
Resize the NvimTree window to the given size. Example: `:NvimTreeresize 50`
5959
resizes the window to the width of 50.
6060

61+
==============================================================================
62+
SETUP *nvim-tree-setup*
63+
64+
To configure the tree (and make it runnable), you should call the setup
65+
function.
66+
67+
>
68+
require'nvim-tree'.setup {
69+
disable_netrw = true,
70+
hijack_netrw = true,
71+
open_on_setup = false,
72+
ignore_ft_on_setup = {},
73+
auto_close = false,
74+
open_on_tab = false,
75+
hijack_cursor = false,
76+
update_cwd = false,
77+
update_focused_file = {
78+
enable = false,
79+
update_cwd = false,
80+
ignore_list = {}
81+
},
82+
system_open = {
83+
cmd = nil,
84+
args = {}
85+
},
86+
}
87+
<
88+
89+
As options are currently being migrated, configuration of global options in
90+
*nvim-tree-options* should be done BEFORE the setup call.
91+
92+
Here is a list of the options available in the setup call:
93+
- |disable_netrw|: completely disable netrw
94+
type: `boolean`
95+
default: `true`
96+
97+
- |hijack_netrw|: hijack netrw windows (overriden if |disable_netrw| is `true`)
98+
type: `boolean`
99+
default: `true`
100+
101+
- |open_on_setup|: will automatically open the tree when running setup if current
102+
buffer is a directory, is empty or is unnamed.
103+
type: `boolean`
104+
default: `false`
105+
106+
- |ignore_ft_on_setup|: list of filetypes that will make |open_on_setup| not
107+
open. You can use this option if you don't want the tree to open in some
108+
scenarios (eg using vim startify).
109+
type: `{string}`
110+
default: `{}`
111+
112+
- |auto_close|: force closing neovim when the tree is the last window in the view.
113+
type: `boolean`
114+
default: `false`
115+
116+
- |open_on_tab|: opens the tree automatically when switching tabpage or opening a new
117+
tabpage if the tree was previously open.
118+
type: `boolean`
119+
default: `false`
120+
121+
- |hijack_cursor|: keeps the cursor on the first letter of the filename when
122+
moving in the tree.
123+
type: `boolean`
124+
default: `false`
125+
126+
- |update_cwd|: changes the tree root directory on `DirChanged` and refreshes
127+
the tree.
128+
type: `boolean`
129+
default: `false`
130+
131+
- |update_focused_file|: update the focused file on `BufEnter`, un-collapses
132+
the folders recursively until it finds the file
133+
134+
- |update_focused_file.enable|: enable this feature.
135+
type: `boolean`
136+
default: `false`
137+
138+
- |update_focused_file.update_cwd|: update the root directory of the tree to the one
139+
of the folder containing the file if the file is not under the current root
140+
directory. Only relevant when |update_focused_file.enable| is `true`
141+
type: `boolean`
142+
default: `false`
143+
144+
- |update_focused_file.ignore_list|: list of buffer names and filetypes that will not
145+
update the root dir of the tree if the file isn't found under the current root
146+
directory. Only relevant when |update_focused_file.update_cwd| is `true` and
147+
|update_focused_file.enable| is `true`.
148+
type: `{string}`
149+
default: `{}`
150+
151+
- |system_open|: configuration options for the system open command
152+
153+
- |system_open.cmd|: the command to run, leaving nil should work but
154+
useful if you want to override the default command with another one.
155+
type: `string`
156+
default: `nil`
157+
158+
- |system_open.args|: the command arguments as a list
159+
type: `{string}`
160+
default: `{}`
161+
61162
==============================================================================
62163
OPTIONS *nvim-tree-options*
63164

@@ -166,58 +267,12 @@ You can enable file highlight for git attributes by setting this property.
166267
This can be used with or without the icons.
167268

168269

169-
|g:nvim_tree_follow| *g:nvim_tree_follow*
170-
171-
Can be `0` or `1`. When `1`, will update the cursor to update to the correct
172-
location in the tree on |BufEnter|.
173-
Default is 0
174-
175-
|g:nvim_tree_follow_update_path| *g:nvim_tree_follow_update_path*
176-
177-
Can be `0` or `1`. When `1`, will update the path of the current dir if the
178-
file is not inside the tree. Works only with |g:nvim_tree_follow| = 1.
179-
Default is 0
180-
181-
|g:nvim_tree_auto_open| *g:nvim_tree_auto_open*
182-
183-
Can be `0` or `1`. When `1`, will open the tree when the package is loaded.
184-
It's not relying on VimEnter anymore.
185-
Default is 0
186-
187-
|g:nvim_tree_auto_close| *g:nvim_tree_auto_close*
188-
189-
Can be `0` or `1`. When `1`, will bind |BufEnter| to automatically
190-
close the tree if it's the last window.
191-
Default is 0
192-
193-
|g:nvim_tree_auto_ignore_ft| *g:nvim_tree_auto_ignore_ft*
194-
195-
Don't auto open the tree on specific filetypes.
196-
Useful when you don't want to open tree on plugins like 'Startify'
197-
Default is {}
198-
>
199-
example: let g.nvim_tree_auto_ignore_ft = {'startify', 'dashboard'}
200-
201270
|g:nvim_tree_quit_on_open| *g:nvim_tree_quit_on_open*
202271

203272
Can be `0` or `1`. When `1`, will close the tree when a file is opened.
204273
Applies to: `edit`, `vsplit`, `split`, `tabnew`.
205274
Default is 0
206275

207-
|g:nvim_tree_system_open_command| *g:nvim_tree_system_open_command*
208-
209-
A string containing the command used to open a file/folder with default system
210-
application. If left unset it will be automatically filled with the right
211-
command, depending on the operating system. If your operating system isn't
212-
recognized or if you want to use another command you can edit it.
213-
Default: depends on the operating system
214-
215-
|g:nvim_tree_system_open_command_args| *g:nvim_tree_system_open_command_args*
216-
217-
An array of strings containing the arguments to be passed to the command
218-
specified in |g:nvim_tree_system_open_command|.
219-
Default: unset if not using Windows
220-
221276
|g:nvim_tree_disable_keybindings| *g:nvim_tree_disable_keybindings*
222277

223278
Can be `0` or `1`. When `1`, will disable all keybindings by the plugin.
@@ -246,30 +301,12 @@ In what format to show root folder. See `:help filename-modifiers` for
246301
available options.
247302
Default is `:~`
248303

249-
|g:nvim_tree_tab_open| *g:nvim_tree_tab_open*
250-
251-
Can be 0 or 1. When 1, will open the tree when entering a new tab if the
252-
tree was previously open.
253-
Default is 0
254-
255304
|g:nvim_tree_auto_resize| *g:nvim_tree_auto_resize*
256305

257306
Can be 0 or 1. When 1, it will resize the tree to it's saved width
258307
when opening a new file.
259308
Default is 1
260309

261-
|g:nvim_tree_hijack_netrw| *g:nvim_tree_hijack_netrw*
262-
263-
Can be 0 or 1. When 1, disable netrw buffers when nvim-tree start but keeps
264-
existing netrw functionnalities accross buffers (like `gx`).
265-
1 by default.
266-
267-
|g:nvim_tree_disable_netrw| *g:nvim_tree_disable_netrw*
268-
269-
Can be 0 or 1. When 1, completely disable netrw and all related
270-
functionnalities.
271-
1 by default.
272-
273310
|g:nvim_tree_add_trailing| *g:nvim_tree_add_trailing*
274311

275312
Can be 0 or 1. When 1, appends a trailing slash to folder names.
@@ -324,12 +361,6 @@ selectable. The default table is
324361
}
325362
<
326363

327-
|g:nvim_tree_hijack_cursor| *g:nvim_tree_hijack_cursor*
328-
329-
Can be 0 or 1. 1 by default.
330-
When 1, moving cursor in the tree will position the cursor at the start
331-
of the file on the current line.
332-
333364
|g:nvim_tree_icon_padding| *g:nvim_tree_icon_padding*
334365

335366
One space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
@@ -338,12 +369,6 @@ One space by default, used for rendering the space between the icon and the file
338369

339370
Defaults to ' ➛ '. Used as a separator between symlinks' source and target.
340371

341-
|g:nvim_tree_update_cwd|
342-
343-
Can be 0 or 1. 0 by default.
344-
Will update the tree cwd when changing nvim's directory (DirChanged event).
345-
WARNING: Behaves strangely with autochdir set.
346-
347372
|g:nvim_tree_respect_buf_cwd| *g:nvim_tree_respect_buf_cwd*
348373

349374
Can be 0 or 1. 0 by default.

0 commit comments

Comments
 (0)