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

[question] Commands like ToggleTermNewSplit, ToggleTermNewTab. #601

Open
mikew opened this issue Aug 8, 2024 · 1 comment
Open

[question] Commands like ToggleTermNewSplit, ToggleTermNewTab. #601

mikew opened this issue Aug 8, 2024 · 1 comment

Comments

@mikew
Copy link

mikew commented Aug 8, 2024

Really like this plugin! But I'm not a fan of how <count><open_mapping> works. Seems like when I'm in a terminal, it opens new splits, when I'm in a file, it opens a new terminal).

I'd much rather have my mapping show/hide/create an initial terminal, and explicit :ToggleTermNewSplit and :ToggleTermNewTab commands. When I go to open a new terminal / split, I don't want to have to know how many terminals I've opened already, I just want a new one.

I'm guessing this is something people can write themselves, but was wondering if anyone had any pointers.

@jeanprbt
Copy link

@mikew I found a way to do so using the following ! I mapped it to a custom key binding, which is only available in terminal mode. It detects the current term(s) direction and simply toggle a new one using the same direction. Hope it helps !

function _G.open_next_terminal()
	local terminals = terms.get_all()
	local direction = terminals[1].direction
	Terminal:new({
		close_on_exit = true,
		direction = direction,
	}):toggle()
end

vim.api.nvim_set_keymap(
	"t",
	"<leader>tt",
	"<cmd>lua open_next_terminal()<CR>",
	{ noremap = true, silent = true }
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants