summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/keymappings.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/keymappings.lua')
-rw-r--r--.config/nvim/lua/keymappings.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/.config/nvim/lua/keymappings.lua b/.config/nvim/lua/keymappings.lua
new file mode 100644
index 0000000..3b6a95a
--- /dev/null
+++ b/.config/nvim/lua/keymappings.lua
@@ -0,0 +1,78 @@
+-- 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 })
+
+-- TODO fix this
+-- Terminal window navigation
+vim.cmd [[
+ tnoremap <C-h> <C-\><C-N><C-w>h
+ tnoremap <C-j> <C-\><C-N><C-w>j
+ tnoremap <C-k> <C-\><C-N><C-w>k
+ tnoremap <C-l> <C-\><C-N><C-w>l
+ inoremap <C-h> <C-\><C-N><C-w>h
+ inoremap <C-j> <C-\><C-N><C-w>j
+ inoremap <C-k> <C-\><C-N><C-w>k
+ inoremap <C-l> <C-\><C-N><C-w>l
+ tnoremap <Esc> <C-\><C-n>
+]]
+
+-- 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
+
+-- better indenting
+vim.api.nvim_set_keymap("v", "<", "<gv", { noremap = true, silent = true })
+vim.api.nvim_set_keymap("v", ">", ">gv", { noremap = true, silent = true })
+
+-- 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 })
+
+-- 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 })
+
+-- 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 })
+
+-- 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 })
+
+-- 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 })
+
+-- Better nav for omnicomplete
+vim.cmd 'inoremap <expr> <c-j> ("\\<C-n>")'
+vim.cmd 'inoremap <expr> <c-k> ("\\<C-p>")'
+
+vim.cmd 'vnoremap p "0p'
+vim.cmd 'vnoremap P "0P'
+
+-- Toggle the QuickFix window
+vim.api.nvim_set_keymap("", "<C-q>", ":call QuickFixToggle()<CR>", { noremap = true, silent = true })
+
+-- Telescope stuff
+-- vim.api.nvim_set_keymap("n", "<Leader>fb", "<cmd>lua require'telescope.builtin'.buffers{}<CR>", { noremap = true, silent = true }) -- search open buffers
+-- vim.api.nvim_set_keymap("n", "<Leader>fl", "<cmd>lua require'telescope.builtin'.current_buffer_fuzzy_find{}<CR>", { noremap = true, silent = true }) -- search lines in current buffer
+-- vim.api.nvim_set_keymap("n", "<Leader>gg", "<cmd>lua require'telescope.builtin'.live_grep{}<CR>", { noremap = true, silent = true }) -- search all lines in project
+-- vim.api.nvim_set_keymap("n", "<Leader>fr", "<cmd>lua require'telescope.builtin'.lsp_references{}<CR>", { noremap = true, silent = true }) -- search references to symbol under cursor