Closed etrnal70 closed 8 months ago
Hi, glad you like the plugin!
I'm not entirely sure but this should work natively in nvim... it seems to work for me (unrelated to flatten).
If it doesn't however and what I'm experiencing is from another plugin, I think this is outside the scope of what flatten is intended to do. Using gf
to open a file in the nvim terminal doesn't open a nested instance, so this would be adding a completely separate feature to the plugin.
Using gf to open a file in the nvim terminal doesn't open a nested instance, so this would be adding a completely separate feature to the plugin.
@willothy supporting gf
in a terminal buffer would be useful for me so that I can have the benefit of the window: { open = "alternate" }
option for both nvim ...
as well as gf
/gF
when used in a terminal buffer. The consistency would nice. I can't seem to find another plugin that does this. I can see however that this feature is a bit orthogonal to flatten's purpose. Any pointers?
Edit: I was able to get something working using an internal API from the plugin, but I don't know how robust this will be!
vim.keymap.set("n", "gf", function()
if vim.bo.buftype == "terminal" then
-- if in a terminal, use flatten to open the file
require("flatten.core").edit_files({
files = { vim.fn.expand("<cfile>") },
stdin = {},
argv = {},
guest_cwd = vim.fn.getcwd(),
force_blocking = false,
response_pipe = "",
})
else
-- otherwise use original gf
vim.cmd("normal! gf")
end
end, { desc = "Open file" })
Using gf to open a file in the nvim terminal doesn't open a nested instance, so this would be adding a completely separate feature to the plugin.
@willothy supporting
gf
in a terminal buffer would be useful for me so that I can have the benefit of thewindow: { open = "alternate" }
option for bothnvim ...
as well asgf
/gF
when used in a terminal buffer. The consistency would nice. I can't seem to find another plugin that does this. I can see however that this feature is a bit orthogonal to flatten's purpose. Any pointers?
Totally, I would quite like that feature too tbh. I will have to look into gf to see if I could use autocmds to interrupt the process. If I can come up with a consistent solution that works without changing default mappings I will maybe include it as an opt-in feature or at least a config snippet.
Overriding the mapping definitely will work for some configs, nice work! In the callback, could also use vim.fn.winnr("#")
to get the alternate window and just set its buffer to vim.fn.bufnr(vim.fn.expand("<cfile>"))
I think, since that's the only thing edit_files
is really doing here as far as I can tell :)
Is your feature request related to a problem? Please describe. As i'm using neovim terminal quite extensively, i do often use
gf
command to jump from an error message directly to the filepath. Would be cool to have this integrated too in flatten. Thank you for the plugin too !Describe the solution you'd like Using
gf
on something like linter output that has a filepath will reuse existing bufferDescribe alternatives you've considered nil
Additional context Linter example