-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
[Feature Request] Next/Previous Terminal #525
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
I currently get around this with the following code: local function get_term_index(current_id, terms)
local idx
for i, v in ipairs(terms) do
if v.id == current_id then
idx = i
end
end
return idx
end
local function go_prev_term()
local current_id = vim.b.toggle_number
if current_id == nil then
return
end
local terms = require("toggleterm.terminal").get_all(true)
local prev_index
local index = get_term_index(current_id, terms)
if index > 1 then
prev_index = index - 1
else
prev_index = #terms
end
require("toggleterm").toggle(terms[index].id)
require("toggleterm").toggle(terms[prev_index].id)
end
local function go_next_term()
local current_id = vim.b.toggle_number
if current_id == nil then
return
end
local terms = require("toggleterm.terminal").get_all(true)
local next_index
local index = get_term_index(current_id, terms)
if index == #terms then
next_index = 1
else
next_index = index + 1
end
require("toggleterm").toggle(terms[index].id)
require("toggleterm").toggle(terms[next_index].id)
end
vim.keymap.set({ "n", "t" }, "<F9>", "<cmd>ToggleTerm<cr>", { desc = "Toggle term" })
vim.keymap.set({ "n", "t" }, "<F8>", function()
go_next_term()
end, { desc = "Toggle term" })
vim.keymap.set({ "n", "t" }, "<F7>", function()
go_prev_term()
end, { desc = "Toggle term" })
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like to have multiple terminals active at once, but only one visible at a time.
Switching between them is much easier if I can just go to previous/next terminal rather than opening them by their number.
Would be great to have dedicated Next/Prev Terminal action/function which is also accessible when a terminal is opened.
The text was updated successfully, but these errors were encountered: