Skip to content

add option to use width as percentage #462

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

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and
let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
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
let g:nvim_tree_width_allow_resize = 1 "0 by default, will not resize the tree when opening a file
let g:nvim_tree_width_as_percent = 1 "0 by default, will treat g:nvim_tree_width as percentage of editor width
let g:nvim_tree_disable_netrw = 0 "1 by default, disables netrw
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)
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
Expand Down
6 changes: 6 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ Can be 0 or 1. When 1, it will not resize the tree to it's original width
when opening a new file.
Default is 0

|g:nvim_tree_width_as_percent| *g:nvim_tree_width_as_percent*

Can be `0` or `1`. When `1`, it will consider the tree width to be a percentage of
the editor's and expect *g:nvim_tree_width* to be any value from *0-100*.
Default is 0

|g:nvim_tree_hijack_netrw| *g:nvim_tree_hijack_netrw*

Can be 0 or 1. When 1, disable netrw buffers when nvim-tree start but keeps
Expand Down
11 changes: 10 additions & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,16 @@ function M.open()
a.nvim_command("vsp")
local move_to = move_tbl[M.View.side]
a.nvim_command("wincmd "..move_to)
a.nvim_command("vertical resize "..M.View.width)

local width
if vim.g.nvim_tree_width_as_percent == 1 then
local percent_as_decimal = M.View.width / 100
width = math.floor(vim.o.columns * percent_as_decimal)
else
width = M.View.width
end
a.nvim_command("vertical resize "..width)

local winnr = a.nvim_get_current_win()
M.View.tabpages[a.nvim_get_current_tabpage()] = winnr
for k, v in pairs(M.View.winopts) do
Expand Down