Comments (14)
Lazy is problematic and results in issues like these.
Please attempt a clean room replication so that we may rule out lazy.
from nvim-tree.lua.
@stentibbing , I was able to get the floating preview with lazy using this config. Hope it helps
return {
"nvim-tree/nvim-tree.lua",
version = "*",
lazy = false,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
local HEIGHT_RATIO = 0.8 -- You can change this
local WIDTH_RATIO = 0.5 -- You can change this too
require("nvim-tree").setup({
view = {
float = {
enable = true,
open_win_config = function()
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,
},
width = function()
return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
end,
},
})
local keymap = vim.keymap
keymap.set("n", "<leader>ee", "<cmd>NvimTreeToggle<CR>", { desc = "Toggle file explorer"})
keymap.set("n", "<leader>ef", "<cmd>NvimTreeFindFileToggle<CR>", { desc = "Toggle file explorer on current file" })
keymap.set("n", "<leader>ec", "<cmd>NvimTreeCollapse<CR>", { desc = "Collapse folders in explorer" })
end,
}
from nvim-tree.lua.
Nice one @hoax3 !
Does that work for you @stentibbing ?
from nvim-tree.lua.
same issue here.
In float mode, on start up nvim-tree should open an empty buffer and render the floating window on top. Which is not the case, it open a wide nvim-tree.
from nvim-tree.lua.
Hi @alex-courtis !
Sorry for the very late response. I did "clean-room replication" and the same problem still exists. Here's the clean room configuration:
`vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
"nvim-tree/nvim-tree.lua",
"nvim-tree/nvim-web-devicons",
-- ADD PLUGINS THAT ARE NECESSARY FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
})
end
if vim.fn.isdirectory(install_path) == 0 then
print("Installing nvim-tree and dependencies.")
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE NECESSARY FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup({
disable_netrw = true,
hijack_netrw = false,
view = {
relativenumber = true,
float = {
enable = true,
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local window_w = screen_w * 0.5
local window_h = screen_h * 0.8
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 {
title = " NvimTree ",
title_pos = "center",
border = "rounded",
relative = "editor",
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
},
})
end
-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
callback = function()
vim.lsp.start { cmd = { "lua-language-server" } }
end,
})
]]
`
So if you open nvim with "nvim -nu init.lua" and then use the command :NvimTreeOpen, everything works as expected. The tree is floating. BUT, if you open current folder with a command "nvim . -nu init.lua" and then do :NvimTreeOpen, the tree is full screen.
from nvim-tree.lua.
I tried a few options and hijack_netrw = false
does the trick when you use nvim .
but nvim /path/anywhere/
does not set the new working directory. And then using nvim
open the default nvim page and nvim-tree open a wide tree.
from nvim-tree.lua.
Thank you, replicated.
Behaves as expected:
- !disable_netrw and !hijack_netrw and netrw not loaded
- netrw loaded
- !disable_netrw and !hijack_netrw
- disable_netrw and !hijack_netrw
- disable_netrw and hijack_netrw
- !disable_netrw and hijack_netrw
It seems that *_netrw are not behaving when netrw is not loaded.
from nvim-tree.lua.
That's working as intended: :help nvim-tree.hijack_directories.enable
directs nvim-tree to open inside the current buffer if it's a directory.
Same behaviour when not using floating.
Please try this:
require("nvim-tree").setup({
-- disable_netrw = true,
-- hijack_netrw = true,
hijack_directories = {
enable = false,
},
---
from nvim-tree.lua.
I do want the hijack_directories, the option:
hijack_directories = {
enable = true,
auto_open = false,
},
does not open the tree on startup but then NvimTreeTroggle still opens this wide tree.
It looks like nvim-tree overrides the unnamed buffer to this wide tree instead of the unnamed buffer + the floating window.
from nvim-tree.lua.
It looks like nvim-tree overrides the unnamed buffer to this wide tree instead of the unnamed buffer + the floating window.
It's actually not an unnamed buffer, it's a buffer with the directory .
. Enter :ls!
to see it.
mkdir foo; nvim -nu nvt-min foo
might make it a bit clearer.
The only purpose of hijack_directories
and hijack_unnamed_buffer_when_opening
is directing the tree to take the place of directory and unnamed buffers.
What's your use case / desired functionality here? If you're looking for startup behaviour you need to add that yourself, see wiki: Open At Startup for rationale and recipes.
from nvim-tree.lua.
Thanks for the explanation, didnt see the wiki.
I made a recording to clarify, in this setup up I have these options:
hijack_unnamed_buffer_when_opening = true,
-- hijack_netrw = false,
disable_netrw = true, -- disable :Explore
hijack_directories = {
enable = true,
auto_open = false,
},
When opening the tree in a No Name or directory buffer, the options of float are not used:
from nvim-tree.lua.
I'm currently facing the same issue.
from nvim-tree.lua.
When opening the tree in a No Name or directory buffer, the options of float are not used.
To clarify: does setting hijack_directories.enable
false result in the desired behaviour? If so, we'll document it.
We don't change default behaviour like this as it will break existing users who exect and rely on it.
from nvim-tree.lua.
Yes when using nvim .
because I have the cwd and the root dir, but not when using nvim /whatever/path
I have .
as root dir and not the path given.
from nvim-tree.lua.
Related Issues (20)
- Float window for full filenames has wrong bg HOT 2
- Right aligned icons HOT 1
- web-devicons default not used HOT 4
- Can't create a file in neovim using nvim-tree.lua(fs_close bad argument #1) HOT 6
- [NvimTree] Could not start the fs_event watcher for path /xxxx/xxxx : ENOSPC HOT 8
- Is it not in the AUR?(Have been solved) HOT 2
- Opening a tree in a new tab messes up local statusline settings HOT 6
- Colors of NvimTree as floating window different as expected (configured) HOT 2
- Unable to open file in new tab HOT 2
- nvim-web-devicons user overrides are clobbered HOT 1
- enable deprecated warnings, minimum neovim version 0.9, harden support for greater versions HOT 3
- Allow nodes to expand until a certain condition is met.
- Diagnostics Disabled flag seems do not work
- `nvim-tree` allows the creation of files over `sshfs`, but they can't be accessed HOT 3
- `nvim-tree` allows the creation of files over `sshfs`, but they can't be accessed HOT 10
- Allow icons to work with any terminal font HOT 1
- Sibling navigation doesn't work with group empty HOT 1
- filesystem_watchers.ignore_dirs and git.disable_for_dirs functions
- The path to open files is always displayed as an absolute path HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-tree.lua.