1
0

add terminal mode keymaps and lua abbr

This commit is contained in:
Rokas Puzonas 2023-05-11 17:30:35 +03:00
parent 4cb5c9eeb5
commit 825d798d2a

View File

@ -5,12 +5,12 @@ local silent = {silent = true}
-- Disable Ex mode
map('n', 'Q', '<nop>')
-- Escape from terminal easier
map('t', '<Esc>', '<C-\\><C-n>')
-- Save file
map('n', '<C-s>', ':w<cr>')
-- Paste from register and not replace it
-- map('x', '<leader>p', '"_dP')
-- Window movement
map('n', '<c-h>', '<c-w>h')
map('n', '<c-j>', '<c-w>j')
@ -37,3 +37,23 @@ map('n', '<A-j>', ':m .+1<CR>==', silent)
map('n', '<A-k>', ':m .-2<CR>==', silent)
map('v', '<A-j>', ":m '>+1<CR>gv=gv", silent)
map('v', '<A-k>', ":m '<-2<CR>gv=gv", silent)
-- Move between windows easier in terminal windows
function _G.set_terminal_keymaps()
local opts = {buffer = 0}
vim.keymap.set('t', '<C-w>', [[<C-\><C-n>]], opts)
vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
end
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
-- Add abbreviation for != => ~= in lua files
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("MyTermOpen", { clear = true }),
pattern = "*.lua",
callback = function()
vim.api.nvim_cmd({ cmd = "abb", args = {"!=", "~="}}, {})
end
})