feat: use lua autocmd to set term keymaps
This commit is contained in:
parent
95e22170e0
commit
c97822479f
@ -7,7 +7,7 @@ vim.cmd([[
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
local function nnoremap(key, command)
|
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
|
end
|
||||||
|
|
||||||
vim.g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
@ -35,16 +35,18 @@ nnoremap("<C-f>", "<Cmd>Telescope grep_string<CR>")
|
|||||||
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
|
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
|
||||||
|
|
||||||
-- terminal
|
-- terminal
|
||||||
function _G.set_terminal_keymaps()
|
vim.api.nvim_create_autocmd("TermOpen", {
|
||||||
local opts = {noremap = true}
|
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', '<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-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-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-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)
|
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
|
||||||
end
|
end,
|
||||||
|
desc = "Map terminal esc and window switch keys",
|
||||||
vim.cmd('autocmd TermOpen term://* lua set_terminal_keymaps()')
|
})
|
||||||
|
|
||||||
-- buffer closing
|
-- buffer closing
|
||||||
nnoremap("<leader>q", ":Bdelete<CR>")
|
nnoremap("<leader>q", ":Bdelete<CR>")
|
||||||
|
Reference in New Issue
Block a user