summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/keymappings.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-07-22 00:08:36 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-07-22 00:08:36 +0200
commitb51f1ae28924a752258e7607fbc3210f9b18eaac (patch)
tree8c8c095528990b3f6eb499dbcca15e9720e636d1 /.config/nvim/lua/keymappings.lua
parentda936b0ed9ac4c171d3c7908e41af1875a82b08b (diff)
Updates based on Chris's lunarvim
Diffstat (limited to '.config/nvim/lua/keymappings.lua')
-rw-r--r--.config/nvim/lua/keymappings.lua166
1 files changed, 106 insertions, 60 deletions
diff --git a/.config/nvim/lua/keymappings.lua b/.config/nvim/lua/keymappings.lua
index 4dfcbb0..e8e3f42 100644
--- a/.config/nvim/lua/keymappings.lua
+++ b/.config/nvim/lua/keymappings.lua
@@ -1,69 +1,115 @@
--- better window movement
-vim.api.nvim_set_keymap("n", "<C-h>", "<C-w>h", { silent = true })
-vim.api.nvim_set_keymap("n", "<C-j>", "<C-w>j", { silent = true })
-vim.api.nvim_set_keymap("n", "<C-k>", "<C-w>k", { silent = true })
-vim.api.nvim_set_keymap("n", "<C-l>", "<C-w>l", { silent = true })
-
--- Terminal window navigation
-vim.api.nvim_set_keymap("t", "<C-h>", "<C-\\><C-N><C-w>h", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("t", "<C-j>", "<C-\\><C-N><C-w>j", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("t", "<C-k>", "<C-\\><C-N><C-w>k", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("t", "<C-l>", "<C-\\><C-N><C-w>l", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("i", "<C-h>", "<C-\\><C-N><C-w>h", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("i", "<C-j>", "<C-\\><C-N><C-w>j", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("i", "<C-k>", "<C-\\><C-N><C-w>k", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("i", "<C-l>", "<C-\\><C-N><C-w>l", {silent = true, noremap = true})
-vim.api.nvim_set_keymap("t", "<Esc>", "<C-\\><C-n>", {silent = true, noremap = true})
-
--- TODO fix this
--- resize with arrows
-if vim.fn.has("mac") == 1 then
- vim.api.nvim_set_keymap("n", "<A-Up>", ":resize -2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<A-Down>", ":resize +2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<A-Left>", ":vertical resize -2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<A-Right>", ":vertical resize +2<CR>", { silent = true })
-else
- vim.api.nvim_set_keymap("n", "<C-Up>", ":resize -2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<C-Down>", ":resize +2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<C-Left>", ":vertical resize -2<CR>", { silent = true })
- vim.api.nvim_set_keymap("n", "<C-Right>", ":vertical resize +2<CR>", { silent = true })
-end
+local utils = require "utils"
+
+local opts = {
+ nnoremap = { noremap = true, silent = true },
+ inoremap = { noremap = true, silent = true },
+ vnoremap = { noremap = true, silent = true },
+ xnoremap = { noremap = true, silent = true },
+ generic = { silent = true },
+}
+
+local default_keys = {
+ insert_mode = {
+ -- I hate escape
+ { "jk", "<ESC>" },
+ { "kj", "<ESC>" },
+ { "jj", "<ESC>" },
+ -- Move current line / block with Alt-j/k ala vscode.
+ { "<A-j>", "<Esc>:m .+1<CR>==gi" },
+ { "<A-k>", "<Esc>:m .-2<CR>==gi" },
+ -- navigation
+ { "<A-Up>", "<C-\\><C-N><C-w>h" },
+ { "<A-Down>", "<C-\\><C-N><C-w>j" },
+ { "<A-Left>", "<C-\\><C-N><C-w>k" },
+ { "<A-Right>", "<C-\\><C-N><C-w>l" },
+ },
+
+ normal_mode = {
+ -- Better window movement
+ { "<C-h>", "<C-w>h" },
+ { "<C-j>", "<C-w>j" },
+ { "<C-k>", "<C-w>k" },
+ { "<C-l>", "<C-w>l" },
+
+ -- Resize with arrows
+ { "<C-Up>", ":resize -2<CR>" },
+ { "<C-Down>", ":resize +2<CR>" },
+ { "<C-Left>", ":vertical resize -2<CR>" },
+ { "<C-Right>", ":vertical resize +2<CR>" },
+
+ -- Tab switch buffer
+ -- { "<TAB>", ":bnext<CR>" },
+ -- { "<S-TAB>", ":bprevious<CR>" },
+
+ -- Move current line / block with Alt-j/k a la vscode.
+ { "<A-j>", ":m .+1<CR>==" },
+ { "<A-k>", ":m .-2<CR>==" },
--- better indenting
-vim.api.nvim_set_keymap("v", "<", "<gv", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("v", ">", ">gv", { noremap = true, silent = true })
+ -- QuickFix
+ { "]q", ":cnext<CR>" },
+ { "[q", ":cprev<CR>" },
+ { "<C-q>", ":call QuickFixToggle()<CR>" },
--- I hate escape
-vim.api.nvim_set_keymap("i", "jk", "<ESC>", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("i", "kj", "<ESC>", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("i", "jj", "<ESC>", { noremap = true, silent = true })
+ -- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
+ },
--- Tab switch buffer
-vim.api.nvim_set_keymap("n", "<TAB>", ":bnext<CR>", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("n", "<S-TAB>", ":bprevious<CR>", { noremap = true, silent = true })
+ term_mode = {
+ -- Terminal window navigation
+ { "<C-h>", "<C-\\><C-N><C-w>h" },
+ { "<C-j>", "<C-\\><C-N><C-w>j" },
+ { "<C-k>", "<C-\\><C-N><C-w>k" },
+ { "<C-l>", "<C-\\><C-N><C-w>l" },
+ },
--- Move selected line / block of text in visual mode
-vim.api.nvim_set_keymap("x", "K", ":move '<-2<CR>gv-gv", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("x", "J", ":move '>+1<CR>gv-gv", { noremap = true, silent = true })
+ visual_mode = {
+ -- Better indenting
+ { "<", "<gv" },
+ { ">", ">gv" },
--- Move current line / block with Alt-j/k ala vscode.
-vim.api.nvim_set_keymap("n", "<A-j>", ":m .+1<CR>==", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("n", "<A-k>", ":m .-2<CR>==", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("i", "<A-j>", "<Esc>:m .+1<CR>==gi", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("i", "<A-k>", "<Esc>:m .-2<CR>==gi", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("x", "<A-j>", ":m '>+1<CR>gv-gv", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("x", "<A-k>", ":m '<-2<CR>gv-gv", { noremap = true, silent = true })
+ -- { "p", '"0p', { silent = true } },
+ -- { "P", '"0P', { silent = true } },
+ },
--- QuickFix
-vim.api.nvim_set_keymap("n", "]q", ":cnext<CR>", { noremap = true, silent = true })
-vim.api.nvim_set_keymap("n", "[q", ":cprev<CR>", { noremap = true, silent = true })
+ visual_block_mode = {
+ -- Move selected line / block of text in visual mode
+ { "K", ":move '<-2<CR>gv-gv" },
+ { "J", ":move '>+1<CR>gv-gv" },
--- Better nav for omnicomplete
-vim.cmd 'inoremap <expr> <c-j> ("\\<C-n>")'
-vim.cmd 'inoremap <expr> <c-k> ("\\<C-p>")'
+ -- Move current line / block with Alt-j/k ala vscode.
+ { "<A-j>", ":m '>+1<CR>gv-gv" },
+ { "<A-k>", ":m '<-2<CR>gv-gv" },
+ },
+}
+
+if vim.fn.has "mac" == 1 then
+ -- TODO: fix this
+ default_keys.normal_mode[5][1] = "<A-Up>"
+ default_keys.normal_mode[6][1] = "<A-Down>"
+ default_keys.normal_mode[7][1] = "<A-Left>"
+ default_keys.normal_mode[8][1] = "<A-Right>"
+end
+
+if O.keys.leader_key == " " or O.keys.leader_key == "space" then
+ vim.g.mapleader = " "
+else
+ vim.g.mapleader = O.keys.leader_key
+end
+
+local function get_user_keys(mode)
+ if O.keys[mode] == nil then
+ return default_keys[mode]
+ else
+ return O.keys[mode]
+ end
+end
-vim.cmd 'vnoremap p "0p'
-vim.cmd 'vnoremap P "0P'
+utils.add_keymap_normal_mode(opts.nnoremap, get_user_keys "normal_mode")
+utils.add_keymap_insert_mode(opts.inoremap, get_user_keys "insert_mode")
+utils.add_keymap_visual_mode(opts.vnoremap, get_user_keys "visual_mode")
+utils.add_keymap_visual_block_mode(opts.xnoremap, get_user_keys "visual_block_mode")
+utils.add_keymap_term_mode(opts.generic, get_user_keys "term_mode")
--- Toggle the QuickFix window
-vim.api.nvim_set_keymap("", "<C-q>", ":call QuickFixToggle()<CR>", { noremap = true, silent = true })
+-- navigate tab completion with <c-j> and <c-k>
+-- runs conditionally
+vim.cmd 'inoremap <expr> <C-j> pumvisible() ? "\\<C-n>" : "\\<C-j>"'
+vim.cmd 'inoremap <expr> <C-k> pumvisible() ? "\\<C-p>" : "\\<C-k>"'