Giter Site home page Giter Site logo

Combining with `gf` about flatten.nvim HOT 3 CLOSED

etrnal70 avatar etrnal70 commented on June 29, 2024
Combining with `gf`

from flatten.nvim.

Comments (3)

willothy avatar willothy commented on June 29, 2024

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.

from flatten.nvim.

brentd avatar brentd commented on June 29, 2024

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" })

from flatten.nvim.

willothy avatar willothy commented on June 29, 2024

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?

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 :)

from flatten.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.