hedyhli / outline.nvim

Code outline sidebar powered by LSP. Forked from symbols-outline.nvim.
https://sr.ht/~hedy/outline.nvim
MIT License
616 stars 17 forks source link

How to set outline window to auto close after code window closed? #86

Closed mengq627 closed 1 month ago

mengq627 commented 2 months ago

when I open outline window and code window, if I close code window by :wq, I need to close outline window by :q again. I have not seen related configuration in doc.

oskarrrrrrr commented 2 months ago

I think it's not possible right now, but I would like this feature as well :)

hedyhli commented 1 month ago

I recommend having a keybinding or some other way so you can easily :qa or :wqa. Personally I use a keybinding for this and would use it whenever I want to exit neovim, regardless of how many windows are open.

mengq627 commented 1 month ago

I recommend having a keybinding or some other way so you can easily :qa or :wqa. Personally I use a keybinding for this and would use it whenever I want to exit neovim, regardless of how many windows are open.

That's good, it is useful. However, I have not set plugin which can open&edit multiple file at same time, I don't know what to do when closing one of multiple files , is this method still valid?

hedyhli commented 1 month ago

qa/wqa closes multiple buffers and windows. And you can use to close both the outline and the code window, or if the outline isn't open at all.

An autocmd can also be used that closes neovim when a window is closed and the outline is the last one remaining, so I wouldn't really consider this something outline.nvim needs to support.

niderhoff commented 1 month ago

I am using this autocmd and it seems to work. When entering a buffer is triggered it checks that the buffer filetype is Outline and if we are in the last remaining window, it will close neovim.

vim.api.nvim_create_autocmd("BufEnter", {
    callback = function()
        if vim.bo.filetype == "Outline" and vim.fn.winnr('$') == 1 then
            vim.cmd("q")
        end
    end,
})
mengq627 commented 1 month ago

I am using this autocmd and it seems to work. When entering a buffer is triggered it checks that the buffer filetype is Outline and if we are in the last remaining window, it will close neovim.

vim.api.nvim_create_autocmd("BufEnter", {
    callback = function()
        if vim.bo.filetype == "Outline" and vim.fn.winnr('$') == 1 then
            vim.cmd("q")
        end
    end,
})

It's so great, help me a lot. So thanks! 😆