aboutsummaryrefslogtreecommitdiff
path: root/lua/gabrielgio/term.lua
blob: 0bd56752463f5bee064f85abac9b8cf60ff33f1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local key = require("gabrielgio.key")

require("toggleterm").setup()

local function isempty(s)
	return s == nil or s == ""
end

local lastCommand = ""

key.nnoremap("<C-n>", ":Neogit kind=replace<cr>")
key.nnoremap("<C-p>", ":ToggleTerm size=40 direction=float<cr>")
key.nnoremap("<C-l>", ":ToggleTerm size=100 direction=vertical<cr>")
key.vnoremap("<C-y>", ":ToggleTermSendVisualSelection<cr>")
key.nnoremap("<C-y>", function()
	local user_input = vim.fn.input("$ ")

	if isempty(user_input) then
		user_input = lastCommand
	end

	if not isempty(user_input) then
		vim.cmd(string.format("TermExec cmd='%s'", user_input))
		lastCommand = user_input
	end
end)
key.tnoremap("<Esc>", "<C-\\><C-n>")
key.tnoremap("<C-p>", "<C-\\><C-n>:ToggleTerm<cr>")
key.tnoremap("<C-l>", "<C-\\><C-n>:ToggleTerm<cr>")