Skip to content

Commit 7cb6897

Browse files
authored
feature: add feature to increase/decrease size (#1048)
1 parent ceadf83 commit 7cb6897

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ let g:nvim_tree_icons = {
9090
nnoremap <C-n> :NvimTreeToggle<CR>
9191
nnoremap <leader>r :NvimTreeRefresh<CR>
9292
nnoremap <leader>n :NvimTreeFindFile<CR>
93-
" NvimTreeOpen, NvimTreeClose, NvimTreeFocus, NvimTreeFindFileToggle, and NvimTreeResize are also available if you need them
93+
" More available functions:
94+
" NvimTreeOpen
95+
" NvimTreeClose
96+
" NvimTreeFocus
97+
" NvimTreeFindFileToggle
98+
" NvimTreeResize
9499
95100
set termguicolors " this variable must be enabled for colors to be applied properly
96101

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ Print clipboard content for both cut and copy
6161
|:NvimTreeResize| *:NvimTreeResize*
6262

6363
Resize the NvimTree window to the given size. Example: `:NvimTreeResize 50`
64-
resizes the window to the width of 50.
64+
resizes the window to the width of 50. If the size starts with "+" or "-" it
65+
adds or removes the given value to the current window width.
66+
Example `:NvimTreeResize -20` removes the value 20 from the current width. And
67+
`:NvimTreeResize +20` adds the value 20 to the current width.
68+
6569

6670
==============================================================================
6771
SETUP *nvim-tree.setup*

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ local function setup_vim_commands()
276276
command! NvimTreeClipboard lua require'nvim-tree.actions.copy-paste'.print_clipboard()
277277
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
278278
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
279-
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize(<args>)
279+
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize("<args>")
280280
]]
281281
end
282282

lua/nvim-tree/view.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,24 @@ function M.open(options)
175175
end
176176

177177
function M.resize(size)
178+
if type(size) == "string" then
179+
size = vim.trim(size)
180+
local first_char = size:sub(1, 1)
181+
size = tonumber(size)
182+
183+
if first_char == "+" or first_char == "-" then
184+
size = M.View.width + size
185+
end
186+
end
187+
188+
if type(size) ~= "number" then
189+
return
190+
end
191+
192+
if size <= 0 then
193+
return
194+
end
195+
178196
if size then
179197
M.View.width = size
180198
M.View.height = size

0 commit comments

Comments
 (0)