feat: use lua autocmd to set term keymaps

This commit is contained in:
mandlm 2022-04-27 11:27:15 +02:00
parent 95e22170e0
commit c97822479f
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7

View File

@ -7,7 +7,7 @@ vim.cmd([[
]])
local function nnoremap(key, command)
vim.api.nvim_set_keymap("n", key, command, {noremap = true})
vim.api.nvim_set_keymap("n", key, command, { noremap = true })
end
vim.g.mapleader = " "
@ -35,16 +35,18 @@ nnoremap("<C-f>", "<Cmd>Telescope grep_string<CR>")
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
-- terminal
function _G.set_terminal_keymaps()
local opts = {noremap = true}
vim.api.nvim_create_autocmd("TermOpen", {
pattern = "term://*",
callback = function()
local opts = { noremap = true }
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-h>', [[<C-\><C-n><C-W>h]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n><C-W>j]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-k>', [[<C-\><C-n><C-W>k]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
end
vim.cmd('autocmd TermOpen term://* lua set_terminal_keymaps()')
end,
desc = "Map terminal esc and window switch keys",
})
-- buffer closing
nnoremap("<leader>q", ":Bdelete<CR>")