Skip to content

feature: add feature to increase/decrease size #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ let g:nvim_tree_icons = {
nnoremap <C-n> :NvimTreeToggle<CR>
nnoremap <leader>r :NvimTreeRefresh<CR>
nnoremap <leader>n :NvimTreeFindFile<CR>
" 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

Expand Down
6 changes: 5 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(<args>)
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize("<args>")
]]
end

Expand Down
18 changes: 18 additions & 0 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down