mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-28 22:08:12 +02:00
[Refactor] Adopt which key mapping style (#1210)
* Refactor keymappings to match which-key style * Update confif example + remove redundant way of registering mappings
This commit is contained in:
parent
8e88bf5258
commit
6d14d7b5da
6 changed files with 70 additions and 84 deletions
|
@ -2,8 +2,8 @@ lvim.builtin.bufferline = {
|
||||||
keymap = {
|
keymap = {
|
||||||
values = {
|
values = {
|
||||||
normal_mode = {
|
normal_mode = {
|
||||||
{ "<S-l>", ":BufferNext<CR>" },
|
["<S-l>"] = { ":BufferNext<CR>" },
|
||||||
{ "<S-h>", ":BufferPrevious<CR>" },
|
["<S-h>"] = { ":BufferPrevious<CR>" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
|
|
|
@ -42,12 +42,12 @@ M.config = function()
|
||||||
keymap = {
|
keymap = {
|
||||||
values = {
|
values = {
|
||||||
insert_mode = {
|
insert_mode = {
|
||||||
{ "<Tab>", 'pumvisible() ? "<C-n>" : "<Tab>"' },
|
["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"' },
|
||||||
{ "<S-Tab>", 'pumvisible() ? "<C-p>" : "<S-Tab>"' },
|
["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"' },
|
||||||
{ "<C-Space>", "compe#complete()" },
|
["<C-Space>"] = { "compe#complete()" },
|
||||||
{ "<C-e>", "compe#close('<C-e>')" },
|
["<C-e>"] = { "compe#close('<C-e>')" },
|
||||||
{ "<C-f>", "compe#scroll({ 'delta': +4 })" },
|
["<C-f>"] = { "compe#scroll({ 'delta': +4 })" },
|
||||||
{ "<C-d>", "compe#scroll({ 'delta': -4 })" },
|
["<C-d>"] = { "compe#scroll({ 'delta': -4 })" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
|
|
|
@ -9,72 +9,72 @@ local opts = {
|
||||||
local keymaps = {
|
local keymaps = {
|
||||||
insert_mode = {
|
insert_mode = {
|
||||||
-- I hate escape
|
-- I hate escape
|
||||||
{ "jk", "<ESC>" },
|
["jk"] = { "<ESC>" },
|
||||||
{ "kj", "<ESC>" },
|
["kj"] = { "<ESC>" },
|
||||||
{ "jj", "<ESC>" },
|
["jj"] = { "<ESC>" },
|
||||||
-- Move current line / block with Alt-j/k ala vscode.
|
-- Move current line / block with Alt-j/k ala vscode.
|
||||||
{ "<A-j>", "<Esc>:m .+1<CR>==gi" },
|
["<A-j>"] = { "<Esc>:m .+1<CR>==gi" },
|
||||||
{ "<A-k>", "<Esc>:m .-2<CR>==gi" },
|
["<A-k>"] = { "<Esc>:m .-2<CR>==gi" },
|
||||||
-- navigation
|
-- navigation
|
||||||
{ "<A-Up>", "<C-\\><C-N><C-w>k" },
|
["<A-Up>"] = { "<C-\\><C-N><C-w>k" },
|
||||||
{ "<A-Down>", "<C-\\><C-N><C-w>j" },
|
["<A-Down>"] = { "<C-\\><C-N><C-w>j" },
|
||||||
{ "<A-Left>", "<C-\\><C-N><C-w>h" },
|
["<A-Left>"] = { "<C-\\><C-N><C-w>h" },
|
||||||
{ "<A-Right>", "<C-\\><C-N><C-w>l" },
|
["<A-Right>"] = { "<C-\\><C-N><C-w>l" },
|
||||||
},
|
},
|
||||||
|
|
||||||
normal_mode = {
|
normal_mode = {
|
||||||
-- Better window movement
|
-- Better window movement
|
||||||
{ "<C-h>", "<C-w>h" },
|
["<C-h>"] = { "<C-w>h" },
|
||||||
{ "<C-j>", "<C-w>j" },
|
["<C-j>"] = { "<C-w>j" },
|
||||||
{ "<C-k>", "<C-w>k" },
|
["<C-k>"] = { "<C-w>k" },
|
||||||
{ "<C-l>", "<C-w>l" },
|
["<C-l>"] = { "<C-w>l" },
|
||||||
|
|
||||||
-- Resize with arrows
|
-- Resize with arrows
|
||||||
{ "<C-Up>", ":resize -2<CR>" },
|
["<C-Up>"] = { ":resize -2<CR>" },
|
||||||
{ "<C-Down>", ":resize +2<CR>" },
|
["<C-Down>"] = { ":resize +2<CR>" },
|
||||||
{ "<C-Left>", ":vertical resize -2<CR>" },
|
["<C-Left>"] = { ":vertical resize -2<CR>" },
|
||||||
{ "<C-Right>", ":vertical resize +2<CR>" },
|
["<C-Right>"] = { ":vertical resize +2<CR>" },
|
||||||
|
|
||||||
-- Tab switch buffer
|
-- Tab switch buffer
|
||||||
-- { "<TAB>", ":bnext<CR>" },
|
-- { "<TAB>", ":bnext<CR>" },
|
||||||
-- { "<S-TAB>", ":bprevious<CR>" },
|
-- { "<S-TAB>", ":bprevious<CR>" },
|
||||||
|
|
||||||
-- Move current line / block with Alt-j/k a la vscode.
|
-- Move current line / block with Alt-j/k a la vscode.
|
||||||
{ "<A-j>", ":m .+1<CR>==" },
|
["<A-j>"] = { ":m .+1<CR>==" },
|
||||||
{ "<A-k>", ":m .-2<CR>==" },
|
["<A-k>"] = { ":m .-2<CR>==" },
|
||||||
|
|
||||||
-- QuickFix
|
-- QuickFix
|
||||||
{ "]q", ":cnext<CR>" },
|
["]q"] = { ":cnext<CR>" },
|
||||||
{ "[q", ":cprev<CR>" },
|
["[q"] = { ":cprev<CR>" },
|
||||||
{ "<C-q>", ":call QuickFixToggle()<CR>" },
|
["<C-q>"] = { ":call QuickFixToggle()<CR>" },
|
||||||
|
|
||||||
-- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
|
-- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
|
||||||
|
|
||||||
-- LSP
|
-- LSP
|
||||||
{ "gd", "<cmd>lua vim.lsp.buf.definition()<CR>" },
|
["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>" },
|
||||||
{ "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>" },
|
["gD"] = { "<cmd>lua vim.lsp.buf.declaration()<CR>" },
|
||||||
{ "gr", "<cmd>lua vim.lsp.buf.references()<CR>" },
|
["gr"] = { "<cmd>lua vim.lsp.buf.references()<CR>" },
|
||||||
{ "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>" },
|
["gi"] = { "<cmd>lua vim.lsp.buf.implementation()<CR>" },
|
||||||
{ "gl", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })<CR>" },
|
["gl"] = { "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })<CR>" },
|
||||||
{ "gs", "<cmd>lua vim.lsp.buf.signature_help()<CR>" },
|
["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>" },
|
||||||
{ "gp", "<cmd>lua require'lsp.peek'.Peek('definition')<CR>" },
|
["gp"] = { "<cmd>lua require'lsp.peek'.Peek('definition')<CR>" },
|
||||||
{ "K", "<cmd>lua vim.lsp.buf.hover()<CR>" },
|
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>" },
|
||||||
{ "<C-p>", "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
|
["<C-p>"] = { "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
|
||||||
{ "<C-n>", "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
|
["<C-n>"] = { "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
|
||||||
},
|
},
|
||||||
|
|
||||||
term_mode = {
|
term_mode = {
|
||||||
-- Terminal window navigation
|
-- Terminal window navigation
|
||||||
{ "<C-h>", "<C-\\><C-N><C-w>h" },
|
["<C-h>"] = { "<C-\\><C-N><C-w>h" },
|
||||||
{ "<C-j>", "<C-\\><C-N><C-w>j" },
|
["<C-j>"] = { "<C-\\><C-N><C-w>j" },
|
||||||
{ "<C-k>", "<C-\\><C-N><C-w>k" },
|
["<C-k>"] = { "<C-\\><C-N><C-w>k" },
|
||||||
{ "<C-l>", "<C-\\><C-N><C-w>l" },
|
["<C-l>"] = { "<C-\\><C-N><C-w>l" },
|
||||||
},
|
},
|
||||||
|
|
||||||
visual_mode = {
|
visual_mode = {
|
||||||
-- Better indenting
|
-- Better indenting
|
||||||
{ "<", "<gv" },
|
["<"] = { "<gv" },
|
||||||
{ ">", ">gv" },
|
[">"] = { ">gv" },
|
||||||
|
|
||||||
-- { "p", '"0p', { silent = true } },
|
-- { "p", '"0p', { silent = true } },
|
||||||
-- { "P", '"0P', { silent = true } },
|
-- { "P", '"0P', { silent = true } },
|
||||||
|
@ -82,21 +82,21 @@ local keymaps = {
|
||||||
|
|
||||||
visual_block_mode = {
|
visual_block_mode = {
|
||||||
-- Move selected line / block of text in visual mode
|
-- Move selected line / block of text in visual mode
|
||||||
{ "K", ":move '<-2<CR>gv-gv" },
|
["K"] = { ":move '<-2<CR>gv-gv" },
|
||||||
{ "J", ":move '>+1<CR>gv-gv" },
|
["J"] = { ":move '>+1<CR>gv-gv" },
|
||||||
|
|
||||||
-- Move current line / block with Alt-j/k ala vscode.
|
-- Move current line / block with Alt-j/k ala vscode.
|
||||||
{ "<A-j>", ":m '>+1<CR>gv-gv" },
|
["<A-j>"] = { ":m '>+1<CR>gv-gv" },
|
||||||
{ "<A-k>", ":m '<-2<CR>gv-gv" },
|
["<A-k>"] = { ":m '<-2<CR>gv-gv" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if vim.fn.has "mac" == 1 then
|
if vim.fn.has "mac" == 1 then
|
||||||
-- TODO: fix this
|
-- TODO: fix this
|
||||||
keymaps.normal_mode[5][1] = "<A-Up>"
|
keymaps.normal_mode["<A-Up>"] = keymaps.normal_mode["<C-Up>"]
|
||||||
keymaps.normal_mode[6][1] = "<A-Down>"
|
keymaps.normal_mode["<A-Down>"] = keymaps.normal_mode["<C-Down>"]
|
||||||
keymaps.normal_mode[7][1] = "<A-Left>"
|
keymaps.normal_mode["<A-Left>"] = keymaps.normal_mode["<C-Left>"]
|
||||||
keymaps.normal_mode[8][1] = "<A-Right>"
|
keymaps.normal_mode["<A-Right>"] = keymaps.normal_mode["<C-Right>"]
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
|
vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
|
||||||
|
|
|
@ -14,8 +14,8 @@ local mode_adapters = {
|
||||||
-- @param opts The mapping options
|
-- @param opts The mapping options
|
||||||
M.load_mode = function(mode, keymaps, opts)
|
M.load_mode = function(mode, keymaps, opts)
|
||||||
mode = mode_adapters[mode] and mode_adapters[mode] or mode
|
mode = mode_adapters[mode] and mode_adapters[mode] or mode
|
||||||
for _, keymap in ipairs(keymaps) do
|
for key, mapping in pairs(keymaps) do
|
||||||
vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts)
|
vim.api.nvim_set_keymap(mode, key, mapping[1], opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,23 +7,16 @@ lvim.colorscheme = "spacegray"
|
||||||
|
|
||||||
-- keymappings
|
-- keymappings
|
||||||
lvim.leader = "space"
|
lvim.leader = "space"
|
||||||
-- overwrite the key-mappings provided by LunarVim for any mode, or leave it empty to keep them
|
-- overwrite/augment the key-mappings provided by LunarVim for any mode, or leave empty to keep the defaults.
|
||||||
-- lvim.keys.normal_mode = {
|
-- lvim.keys.normal_mode = {
|
||||||
-- Page down/up
|
-- -- Page down/up
|
||||||
-- {'[d', '<PageUp>'},
|
-- ["[d"] = { "<PageUp>" },
|
||||||
-- {']d', '<PageDown>'},
|
-- ["]d"] = { "<PageDown>" },
|
||||||
--
|
--
|
||||||
-- Navigate buffers
|
-- -- Navigate buffers
|
||||||
-- {'<Tab>', ':bnext<CR>'},
|
-- ["<Tab>"] = { ":bnext<CR>" },
|
||||||
-- {'<S-Tab>', ':bprevious<CR>'},
|
-- ["<S-Tab>"] = { ":bprevious<CR>" },
|
||||||
-- }
|
-- }
|
||||||
-- if you just want to augment the existing ones then use the utility function
|
|
||||||
-- require("utils").add_keymap_insert_mode({ silent = true }, {
|
|
||||||
-- { "<C-s>", ":w<cr>" },
|
|
||||||
-- { "<C-c>", "<ESC>" },
|
|
||||||
-- })
|
|
||||||
-- you can also use the native vim way directly
|
|
||||||
-- vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true })
|
|
||||||
|
|
||||||
-- TODO: User Config for predefined plugins
|
-- TODO: User Config for predefined plugins
|
||||||
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
|
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
|
||||||
|
|
|
@ -15,23 +15,16 @@ lvim.lint_on_save = true
|
||||||
lvim.colorscheme = "spacegray"
|
lvim.colorscheme = "spacegray"
|
||||||
-- keymappings
|
-- keymappings
|
||||||
lvim.leader = "space"
|
lvim.leader = "space"
|
||||||
-- overwrite the key-mappings provided by LunarVim for any mode, or leave it empty to keep them
|
-- overwrite/augment the key-mappings provided by LunarVim for any mode, or leave empty to keep the defaults.
|
||||||
-- lvim.keys.normal_mode = {
|
-- lvim.keys.normal_mode = {
|
||||||
-- Page down/up
|
-- -- Page down/up
|
||||||
-- {'[d', '<PageUp>'},
|
-- ["[d"] = { "<PageUp>" },
|
||||||
-- {']d', '<PageDown>'},
|
-- ["]d"] = { "<PageDown>" },
|
||||||
--
|
--
|
||||||
-- Navigate buffers
|
-- -- Navigate buffers
|
||||||
-- {'<Tab>', ':bnext<CR>'},
|
-- ["<Tab>"] = { ":bnext<CR>" },
|
||||||
-- {'<S-Tab>', ':bprevious<CR>'},
|
-- ["<S-Tab>"] = { ":bprevious<CR>" },
|
||||||
-- }
|
-- }
|
||||||
-- if you just want to augment the existing ones then use the utility function
|
|
||||||
-- require("utils").add_keymap_insert_mode({ silent = true }, {
|
|
||||||
-- { "<C-s>", ":w<cr>" },
|
|
||||||
-- { "<C-c>", "<ESC>" },
|
|
||||||
-- })
|
|
||||||
-- you can also use the native vim way directly
|
|
||||||
-- vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true })
|
|
||||||
|
|
||||||
-- TODO: User Config for predefined plugins
|
-- TODO: User Config for predefined plugins
|
||||||
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
|
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue