Skip to content
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

Use escape to close hunk preview #385

Closed
ghost opened this issue Sep 29, 2021 · 9 comments
Closed

Use escape to close hunk preview #385

ghost opened this issue Sep 29, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Sep 29, 2021

gitgutter has an option to close hunk preview windows on escape. See here : https://github.com/airblade/vim-gitgutter/blob/256702dd1432894b3607d3de6cd660863b331818/doc/gitgutter.txt#L351
Would it be possible to implement it in gitsigns?

@ghost ghost added the enhancement New feature or request label Sep 29, 2021
@lewis6991
Copy link
Owner

Is moving the cursor not sufficient?

@gegoune
Copy link
Contributor

gegoune commented Sep 29, 2021

This isn't big issue but I caught myself trying to close hunk preview with Esc many tines, it just feels natural. I then immediately realise I have to move cursor, so it's fine, but I personally think it would be a good addition.

(While I am here, thanks for all your work on gitsigns and impatient plugins, very appreciated! ❤️)

@lewis6991
Copy link
Owner

Ok we can consider doing this then.

@ghost
Copy link
Author

ghost commented Sep 30, 2021

This isn't big issue but I caught myself trying to close hunk preview with Esc many tines, it just feels natural. I then immediately realise I have to move cursor, so it's fine, but I personally think it would be a good addition.

(While I am here, thanks for all your work on gitsigns and impatient plugins, very appreciated! heart)

Exactly this.

@lewis6991
Copy link
Owner

So, had a stab at implementing this and turns out to be a little tricky. The main issue is the preview windows don't automatically get focus when they are shown, which means the mapping would need to be applied to the main buffer. We obviously don't want this mapping to persist, so it needs to be a one-shot mapping, like a ++once autocmd which there is no straight forward way to do.

@gegoune any ideas?

@gegoune
Copy link
Contributor

gegoune commented Oct 18, 2021

I don't know nvim internals enough to suggest anything meaningful, but can you maybe get window id when creating preview window, then create mapping that would close that window and delete mapping on window deletion?

If not, that's fine, I am used to moving cursor now so it's not really a deal breaker at all. Just nice to have.

Thanks for the plugin, it's amazing! ❤️

@lewis6991
Copy link
Owner

I think implementing this will be more trouble than it's worth. Will accept any PR's that implement this well.

@pinbraerts
Copy link

Bind something like this this in on_attach

vim.keymap.set('n', '<esc>', function ()
    for _, id in ipairs(vim.api.nvim_list_wins()) do
        if vim.api.nvim_win_get_config(id).relative ~= "" then
            vim.api.nvim_win_close(id, false)
        end
    end
end, { buffer = buffer })

@patrykk21
Copy link

Bind something like this this in on_attach

vim.keymap.set('n', '<esc>', function ()
    for _, id in ipairs(vim.api.nvim_list_wins()) do
        if vim.api.nvim_win_get_config(id).relative ~= "" then
            vim.api.nvim_win_close(id, false)
        end
    end
end, { buffer = buffer })

Thanks this worked!

Repository owner locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants