File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Plug 'kyazdani42/nvim-tree.lua'
18
18
19
19
``` vim
20
20
let g:nvim_tree_side = 'right' "left by default
21
- let g:nvim_tree_width = 40 "30 by default
21
+ let g:nvim_tree_width = 40 "30 by default, can be width_in_columns or 'width_in_percent%'
22
22
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
23
23
let g:nvim_tree_gitignore = 1 "0 by default
24
24
let g:nvim_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ OPTIONS *nvim-tree-options*
54
54
55
55
| g:nvim_tree_width | *g:nvim_tree_width*
56
56
57
- width of the window (default to 30)
57
+ width of the window, can be *width_in_columns* or *'width_in_percent%'*
58
+ >
59
+ let g:nvim_tree_width = 30 " indicates width of 30 columns
60
+ let g:nvim_tree_width = '30%' " indicates width of 30% of '&columns'
58
61
59
62
| g:nvim_tree_side | *g:nvim_tree_side*
60
63
Original file line number Diff line number Diff line change @@ -214,12 +214,21 @@ function M.focus(winnr, open_if_closed)
214
214
a .nvim_set_current_win (wnr )
215
215
end
216
216
217
+ local function get_width ()
218
+ if type (M .View .width ) == " number" then
219
+ return M .View .width
220
+ end
221
+ local width_as_number = tonumber (M .View .width :sub (0 , - 2 ))
222
+ local percent_as_decimal = width_as_number / 100
223
+ return math.floor (vim .o .columns * percent_as_decimal )
224
+ end
225
+
217
226
function M .resize ()
218
227
if vim .g .nvim_tree_auto_resize == 0 or not a .nvim_win_is_valid (M .get_winnr ()) then
219
228
return
220
229
end
221
230
222
- a .nvim_win_set_width (M .get_winnr (), M . View . width )
231
+ a .nvim_win_set_width (M .get_winnr (), get_width () )
223
232
end
224
233
225
234
local move_tbl = {
@@ -237,7 +246,7 @@ function M.open()
237
246
a .nvim_command (" vsp" )
238
247
local move_to = move_tbl [M .View .side ]
239
248
a .nvim_command (" wincmd " .. move_to )
240
- a .nvim_command (" vertical resize " .. M . View . width )
249
+ a .nvim_command (" vertical resize " .. get_width () )
241
250
local winnr = a .nvim_get_current_win ()
242
251
local tabpage = a .nvim_get_current_tabpage ()
243
252
M .View .tabpages [tabpage ] = vim .tbl_extend (" force" , M .View .tabpages [tabpage ] or {help = false }, {winnr = winnr })
You can’t perform that action at this time.
0 commit comments