chore: simplify keymap declaration
This commit is contained in:
parent
61a96c3c3c
commit
49ca477c15
@ -1,67 +1,87 @@
|
||||
local opt = { noremap = true, silent = true }
|
||||
local keymap = vim.api.nvim_set_keymap
|
||||
-- TODO: Remove this
|
||||
vim.api.nvim_set_keymap('n', '<insert>', '<cmd>Lazy profile<cr>', { noremap = true, silent = true })
|
||||
keymap('n', '<insert>', '<cmd>Lazy profile<cr>', opt)
|
||||
-- resize {{{
|
||||
vim.api.nvim_set_keymap('n', '<c-up>', '<cmd>resize -2<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-down>', '<cmd>resize +2<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-left>', '<cmd>vertical resize -2<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<c-right>', '<cmd>vertical resize -2<cr>', { noremap = true, silent = true })
|
||||
keymap('n', '<c-up>', '<cmd>resize -2<cr>', opt)
|
||||
keymap('n', '<c-down>', '<cmd>resize +2<cr>', opt)
|
||||
keymap('n', '<c-left>', '<cmd>vertical resize -2<cr>', opt)
|
||||
keymap('n', '<c-right>', '<cmd>vertical resize -2<cr>', opt)
|
||||
-- }}}
|
||||
-- indent {{{
|
||||
vim.api.nvim_set_keymap('v', '<', '<gv', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '>', '>gv', { noremap = true, silent = true })
|
||||
keymap('v', '<', '<gv', opt)
|
||||
keymap('v', '>', '>gv', opt)
|
||||
-- }}}
|
||||
-- open/close folds with enter key {{{
|
||||
vim.api.nvim_set_keymap('n', '<cr>', "@=(foldlevel('.')?'za':\"<Space>\")<CR>", { noremap = true, silent = true })
|
||||
keymap('n', '<cr>', "@=(foldlevel('.')?'za':\"<Space>\")<CR>", opt)
|
||||
-- }}}
|
||||
-- terminal {{{
|
||||
vim.api.nvim_set_keymap('n', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('t', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('i', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('n', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('t', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('v', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap('i', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
|
||||
keymap('n', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
|
||||
keymap('t', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
|
||||
keymap('v', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
|
||||
keymap('i', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
|
||||
keymap('n', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
|
||||
keymap('t', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
|
||||
keymap('v', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
|
||||
keymap('i', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
|
||||
-- }}}
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<BS>', ':', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', ';', ':', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', '<leader>rs', ':s///gI<Left><Left><Left><Left><Left><Left>', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', '<leader>rr', ':%s///gI<Left><Left><Left><Left>', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', '<leader>r', ':s///gI<Left><Left><Left><Left>', { noremap = true })
|
||||
keymap('n', '<BS>', ':', { noremap = true })
|
||||
keymap('n', ';', ':', { noremap = true })
|
||||
keymap('n', '<leader>rs', ':s///gI<Left><Left><Left><Left><Left><Left>', { noremap = true })
|
||||
keymap('n', '<leader>rr', ':%s///gI<Left><Left><Left><Left>', { noremap = true })
|
||||
keymap('v', '<leader>r', ':s///gI<Left><Left><Left><Left>', { noremap = true })
|
||||
|
||||
vim.api.nvim_set_keymap('n', '<leader>xl', '<cmd>TroubleToggle loclist<cr>', { silent = true, noremap = true })
|
||||
vim.api.nvim_set_keymap('n', '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', { silent = true, noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'gR', '<cmd>TroubleToggle lsp_references<cr>', { silent = true, noremap = true })
|
||||
vim.api.nvim_set_keymap('n', '<leader>xx', '<cmd>TroubleToggle<cr>', { silent = true, noremap = true })
|
||||
vim.api.nvim_set_keymap(
|
||||
keymap('n', '<leader>xl', '<cmd>TroubleToggle loclist<cr>', { silent = true, noremap = true })
|
||||
keymap('n', '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', { silent = true, noremap = true })
|
||||
keymap('n', 'gR', '<cmd>TroubleToggle lsp_references<cr>', { silent = true, noremap = true })
|
||||
keymap('n', '<leader>xx', '<cmd>TroubleToggle<cr>', { silent = true, noremap = true })
|
||||
keymap(
|
||||
'n',
|
||||
'<leader>xw',
|
||||
'<cmd>TroubleToggle workspace_diagnostics<cr>',
|
||||
{ silent = true, noremap = true }
|
||||
)
|
||||
vim.api.nvim_set_keymap(
|
||||
keymap(
|
||||
'n',
|
||||
'<leader>xd',
|
||||
'<cmd>TroubleToggle document_diagnostics<cr>',
|
||||
{ silent = true, noremap = true }
|
||||
)
|
||||
|
||||
vim.api.nvim_set_keymap('n', 'D', '"_d', { noremap = true })
|
||||
keymap('n', 'D', '"_d', { noremap = true })
|
||||
|
||||
keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
|
||||
keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
|
||||
keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
|
||||
keymap('n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
|
||||
keymap('n', 'gr', '<cmd>TroubleToggle lsp_references<CR>', opt)
|
||||
keymap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
||||
keymap('n', '<leader>lf', '<cmd>lua vim.lsp.buf.format { async = true }<cr>', opt)
|
||||
keymap('n', '<leader>li', '<cmd>LspInfo<cr>', opt)
|
||||
keymap('n', '<leader>lI', '<cmd>LspInstallInfo<cr>', opt)
|
||||
keymap('n', '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>', opt)
|
||||
keymap('n', '<leader>lj', '<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>', opt)
|
||||
keymap('n', '<leader>lk', '<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>', opt)
|
||||
keymap('n', '<leader>lr', '<cmd>lua vim.lsp.buf.rename()<cr>', opt)
|
||||
keymap('n', '<leader>ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
|
||||
keymap('n', '<leader>lq', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
|
||||
keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
||||
|
||||
|
||||
function MapDHM()
|
||||
vim.api.nvim_set_keymap('n', 'i', 'l', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'n', 'j', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'e', 'k', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', 'l', 'i', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', 'i', 'l', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', 'n', 'j', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', 'e', 'k', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'l', 'i', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'N', 'J', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'j', 'n', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', 'J', 'N', { noremap = true })
|
||||
vim.api.nvim_set_keymap('n', '<nop>', 'I', { noremap = true })
|
||||
keymap('n', 'i', 'l', { noremap = true })
|
||||
keymap('n', 'n', 'j', { noremap = true })
|
||||
keymap('n', 'e', 'k', { noremap = true })
|
||||
keymap('v', 'l', 'i', { noremap = true })
|
||||
keymap('v', 'i', 'l', { noremap = true })
|
||||
keymap('v', 'n', 'j', { noremap = true })
|
||||
keymap('v', 'e', 'k', { noremap = true })
|
||||
keymap('n', 'l', 'i', { noremap = true })
|
||||
keymap('n', 'N', 'J', { noremap = true })
|
||||
keymap('n', 'j', 'n', { noremap = true })
|
||||
keymap('n', 'J', 'N', { noremap = true })
|
||||
keymap('n', '<nop>', 'I', { noremap = true })
|
||||
end
|
||||
|
||||
function UnMapDHM()
|
||||
|
Loading…
Reference in New Issue
Block a user