You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Samuel Williams edited this page Dec 5, 2023
·
44 revisions
Before getting started, we should note that many, if not most terminal-toggling plugins are not made to handle navigating away from the terminal automatically upon a new tab opening. As a result, what can happen is that the requested file is opened in a new tab, but the floating terminal is still extant in the initial window that launched the edit request in the first place. This can cause some somewhat quirky behavior, depending on the terminal-toggling plugin you're using.
We can prevent this from occurring by creating an autocmd to dismiss the floating terminal when an edit request is received by the host session. Unception provides a user event that you can hook into. For FTerm, the autocmd could look something like:
vim.api.nvim_create_autocmd(
"User",
{
pattern = "UnceptionEditRequestReceived",
callback = function()
-- Toggle the terminal off.
require('FTerm').toggle()
end
}
)
The idea will be the same for whatever terminal-toggling plugin you're using. You want to dismiss the terminal whenever an edit request is received.
Note that by adding the autocmd above, if you use unception on regular terminal buffers, this will also cause toggling of the floating terminal window. This is probably undesirable, so if your terminal-toggling plugin provides a command which only hides the floating terminal rather than shows or hides it (or you are able to check to ensure that the terminal is currently visible before toggling it), it will be preferable to bind to that instead.
With that out of the way, the next option we want to enable is for the requested buffers to be opened in new tabs. See the following snippet for Packer.nvim:
use
{
"samjwill/nvim-unception",
setup = function()
vim.g.unception_open_buffer_in_new_tab = true
end
}
Voila! Neovim sessions launched from the floating terminal now cause the requested file to be opened in a new tab instead!