From ebe1ffdd00729763e8243d50a9456d900298364a Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Tue, 25 Apr 2023 21:24:43 +0700 Subject: [PATCH] chore: float nvim-tree --- data/nvim/init.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/data/nvim/init.lua b/data/nvim/init.lua index 2fa64fe..a76fece 100644 --- a/data/nvim/init.lua +++ b/data/nvim/init.lua @@ -121,6 +121,33 @@ require("packer").startup(function() "nvim-tree/nvim-tree.lua", config = function() require("nvim-tree").setup({ + view = { + float = { + enable = true, + -- https://www.reddit.com/r/neovim/comments/wvcz64/nvimtreelua_how_to_center_floating_window + -- https://github.com/MarioCarrion/videos/blob/main/2023/01/nvim/lua/plugins/nvim-tree.lua + open_win_config = function() + local HEIGHT_RATIO = 0.8 + local WIDTH_RATIO = 0.5 + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * WIDTH_RATIO + local window_h = screen_h * HEIGHT_RATIO + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() + return { + border = "rounded", + relative = "editor", + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + }, + }, renderer = { group_empty = true, icons = {