-
-
Notifications
You must be signed in to change notification settings - Fork 624
refactor(#1645): remove unused open_replacing_current_buffer #2570
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
Conversation
5808f35
to
e40cc70
Compare
lmao, this broke my config since I mapped |
See |
My workflow is broken as well, but currently, I don't believe it's supported.
Step 3 is not supported. What is described in the docs is step 4 onwards, but this re-arranges the windows in neovim which is not great. If |
I'm on the same boat as @sharkov63 and @steliyan, but I have to agree that the maintenance burden may not be worth it. My motivation for introducing the function local view = require "nvim-tree.view"
local core = require "nvim-tree.core"
local function openReplacingCurrentBuffer(cwd)
if view.is_visible() then
return
end
local buf = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(buf)
if cwd == "" or cwd == nil then
if bufname ~= "" and vim.loop.fs_stat(bufname) ~= nil then
cwd = vim.fn.fnamemodify(bufname, ":p:h")
else
return
end
end
if not core.get_explorer() or cwd ~= core.get_cwd() then
core.init(cwd)
end
view.open_in_win { hijack_current_buf = false, resize = false }
require("nvim-tree.renderer").draw()
require("nvim-tree.actions.finders.find-file").fn(bufname)
end
-- Then use it for whatever purpose you see fit, for instance reimplementing netrw functionality
local function openInPlace(cwd)
if cwd == "" or cwd == nil then
local buf = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(buf)
if bufname ~= "" and vim.loop.fs_stat(bufname) ~= nil then
cwd = vim.fn.fnamemodify(bufname, ":p:h")
else
cwd = vim.loop.cwd()
end
end
openReplacingCurrentBuffer(cwd)
end
--
-- Commands
--
vim.api.nvim_create_user_command("Explore", function(res)
openInPlace(res.args)
end, {
desc = 'Open file explorer in current buffer',
nargs = "?", complete = "dir"
}) |
And why wouldn't you use provided api (#2570 (comment))? |
@gegoune, that api function doesn't seem to work for my usecase. It requires My goal is to replicate netrw functionality. I want to open a nvim-tree window even if it didn't exist and use the provided argument as the working directory for |
You can use |
Thank you @gegoune, that is exactly what I needed! |
This is what I was looking for, thank you very much! |
discovered via #1645