Replies: 3 comments 1 reply
-
Right now you can use
That follows prior art from plugins such as fugitive, showing the more-able output. |
Beta Was this translation helpful? Give feedback.
-
It would be very possible to open a floating terminal at the path with an vim.keymap.set("n", "Z", function()
local node = api.tree.get_node_under_cursor()
local path = vim.fn.fnamemodify(node.absolute_path, ":p:h")
print("do something with " .. path)
end, opts("do something with")) Please do share the recipe for whatever you come up with. |
Beta Was this translation helpful? Give feedback.
-
@alex-courtis , insightful,, thanks, So chat GPT made me this that works fine , I'm not an expert of nvim api, I appreciate your review on it, local function open_floating_terminal()
local node = api.tree.get_node_under_cursor()
if not node then
return
end
local path
if node.type == 'directory' then
path = node.absolute_path
else
path = vim.fn.fnamemodify(node.absolute_path, ":p:h")
end
local term_buf = vim.api.nvim_create_buf(false, true)
local width = vim.o.columns
local height = vim.o.lines
local term_win = vim.api.nvim_open_win(term_buf, true, {
relative = 'editor',
width = math.ceil(width * 0.8),
height = math.ceil(height * 0.8),
col = math.ceil(width * 0.1),
row = math.ceil(height * 0.1),
style = 'minimal',
border = 'rounded'
})
vim.fn.termopen("cd " .. path .. " && zsh")
vim.api.nvim_buf_set_keymap(term_buf, 't', '<Esc>', [[<C-\><C-n>:q<CR>]], { noremap = true, silent = true })
end
vim.keymap.set("n", "Z", open_floating_terminal, { desc = "Open in floating terminal" })
|
Beta Was this translation helpful? Give feedback.
-
Is this a question? No
Please start a new Q&A discussion instead of raising a feature request.
Can this functionality be implemented utilising API?
nvim-tree exposes extensive API (see
:h nvim-tree-api
). Can it be used to achieve your goal? Is there a missing API that would make it possible? probably, maybe, I don't knowGiven stable status of nvim-tree it's preferred to add new API than new functionality.
Is your feature request related to a problem? Please describe.
It happens very usual I need to do file operations (tar, untar, etc) on a file, it will be useful if I can open a floating terminal after bnavigatong on my file in the tree inside vim, its actullay adding a new layer on top of nvim from the nvimtree gateway
Describe the solution you'd like
A clear and concise description of what you want to happen. Title says it all, open the path under cursor in a floating terminal, something like system open, but open in a floating terminal instead
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered. Terminal in a new tab, split, v split etc
Additional context
Add any other context or screenshots about the feature request here.
Beta Was this translation helpful? Give feedback.
All reactions