diff --git a/README.md b/README.md index 49937ce7b9e..f0f8260d787 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,12 @@ let g:nvim_tree_icons = { nnoremap :NvimTreeToggle nnoremap r :NvimTreeRefresh nnoremap n :NvimTreeFindFile -" NvimTreeOpen, NvimTreeClose, NvimTreeFocus, NvimTreeFindFileToggle, and NvimTreeResize are also available if you need them +" More available functions: +" NvimTreeOpen +" NvimTreeClose +" NvimTreeFocus +" NvimTreeFindFileToggle +" NvimTreeResize set termguicolors " this variable must be enabled for colors to be applied properly diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5ac6a81645d..d0e1794700d 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -61,7 +61,11 @@ Print clipboard content for both cut and copy |:NvimTreeResize| *:NvimTreeResize* Resize the NvimTree window to the given size. Example: `:NvimTreeResize 50` -resizes the window to the width of 50. +resizes the window to the width of 50. If the size starts with "+" or "-" it +adds or removes the given value to the current window width. +Example `:NvimTreeResize -20` removes the value 20 from the current width. And +`:NvimTreeResize +20` adds the value 20 to the current width. + ============================================================================== SETUP *nvim-tree.setup* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 9a41ac1713b..fb781cd67b0 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -276,7 +276,7 @@ local function setup_vim_commands() command! NvimTreeClipboard lua require'nvim-tree.actions.copy-paste'.print_clipboard() command! NvimTreeFindFile lua require'nvim-tree'.find_file(true) command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true) - command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize() + command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize("") ]] end diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index bd0f20b35cf..e0333ecaf88 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -175,6 +175,24 @@ function M.open(options) end function M.resize(size) + if type(size) == "string" then + size = vim.trim(size) + local first_char = size:sub(1, 1) + size = tonumber(size) + + if first_char == "+" or first_char == "-" then + size = M.View.width + size + end + end + + if type(size) ~= "number" then + return + end + + if size <= 0 then + return + end + if size then M.View.width = size M.View.height = size