Skip to content

Option to set window.open for each individual file being opened, not once globally #111

Open

Description

@dk949

Is your feature request related to a problem? Please describe.

When using the terminal to open files normally, I like having them open in the alternate window, but for git commit, I would like to be able to do something like:

[open floating window]
vim.cmd.term("git commit")

Such that the editor opens in that floating window.

Describe the solution you'd like

Perhaps a global variable to make it possible to do something like GIT_EDITOR="nvim --cmd 'let g:flatten_window_open=\"current\"'"

Another option could be to let the pre_open hook return a new configuration (or subset of the configuration) which would be applied to just the current window being opened. This is a bit more complicated to work with, but it would solve this question for other config options too, not just window.open.

Describe alternatives you've considered

My current solution seems to work, but it's pretty ugly

-- config:
{
    hooks = {
        post_open = function ()
            require("flatten").config.window.open = "alternate"
        end
    },
}

-- git commit function:

require("flatten").config.window.open = "current"
[open floating window]
vim.cmd.term("git commit")

Activity

  1. willothy commented on May 30, 2025

    @willothy
    Owner

    Yeah, I would definitely like to support this - I've had the need for it as well. I'm pretty busy with work right now but I'll try to get to this soon :)

  2. dk949 commented on May 30, 2025

    @dk949
    Author

    I've got a weekend spare if you accept PRs

    I would personally be in favour of the second solution where pre_open returns the new config to be merged, but it technically could be a breaking change.

  3. willothy commented on May 31, 2025

    @willothy
    Owner

    I'd love a PR! In this solution would pre_open return the config for each window? I might be misunderstanding. I think it should still be possible to set a global default, but having the ability to define custom handlers / determine what to do for individual files would be great too :)

  4. dk949 commented on Jun 1, 2025

    @dk949
    Author

    PR opened. The config returned by pre_open is merged with the global one only for the current file, so users can use guest_data to determine if/how config needs to be updated. returning nil just keeps the old config, so old behaviour is not changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions