A plugin to send a command to the terminal that makes sense. The terminal is picked in that order
- The most recent visible terminal
- If no visible terminal, use the most recent hidden terminal: -- In that case, we show that hidden terminal in its last visible window. -- If its last visible window is closed, use a new window.
Unlike other similar plugins this plugin automatically choose a terminal (the most recent one) so you do not have to "mark" the terminal you want to use.
I mainly use with a keymap to quickly repeat last command (SendToTerm !!).
Like any other plugin add "ilan/nvim-send-to-first-term" to your package manager and call
require("nvim-send-to-first-term").setup().
{
"ilan-schemoul/nvim-send-to-first-term",
opts = {},
}:SendToTerm <command>If no command is provided an input is shown to you so you can type your command.
The last opened, non-hidden, terminal in your current tab is used. If no terminal is found a new one is created and the command is sent to it.
-- Repeat last command
vim.keymap.set("n", "<leader>pr", "<cmd>SendToTerm !!<cr>")
-- Open a ui input so you can type any command
vim.keymap.set("n", "<leader>ps", "<cmd>SendToTerm<cr>")
-- Run make
vim.keymap.set("n", "<leader>ps", "<cmd>SendToTerm make<cr>")