.dotfiles/private_dot_config/nvim/lua/config/keymaps.lua

81 lines
3.2 KiB
Lua

-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
local map = vim.keymap.set
-- Custom movement keys (JKLM instead of HJKL)
map({ "n", "v", "o" }, "j", "h", { desc = "Move left" })
map({ "n", "v", "o" }, "k", "v:count == 0 ? 'gj' : 'j'", { desc = "Move down", expr = true, silent = true })
map({ "n", "v" }, "<Down>", "v:count == 0 ? 'gj' : 'j'", { desc = "Move down", expr = true, silent = true })
map({ "n", "v", "o" }, "l", "v:count == 0 ? 'gk' : 'k'", { desc = "Move up", expr = true, silent = true })
map({ "n", "v" }, "<Up>", "v:count == 0 ? 'gk' : 'k'", { desc = "Move up", expr = true, silent = true })
map({ "n", "v", "o" }, "m", "l", { desc = "Move right" })
map("n", "§", "m", { desc = "Set a mark" })
-- Window navigation
map("n", "<C-j>", "<C-w>h", { desc = "Go to left window" })
map("n", "<C-k>", "<C-w>j", { desc = "Go to lower window" })
map("n", "<C-l>", "<C-w>k", { desc = "Go to upper window" })
map("n", "<C-m>", "<C-w>l", { desc = "Go to right window" })
-- for dadbod-ui buffers, see autocmds.lua
-- Move Lines
map("n", "<A-k>", "<cmd>execute 'move .+' . v:count1<cr>==", { desc = "Move Down" })
map("n", "<A-l>", "<cmd>execute 'move .-' . (v:count1 + 1)<cr>==", { desc = "Move Up" })
map("i", "<A-k>", "<esc><cmd>m .+1<cr>==gi", { desc = "Move Down" })
map("i", "<A-l>", "<esc><cmd>m .-2<cr>==gi", { desc = "Move Up" })
map("v", "<A-k>", ":<C-u>execute \"'<,'>move '>+\" . v:count1<cr>gv=gv", { desc = "Move Down" })
map("v", "<A-l>", ":<C-u>execute \"'<,'>move '<-\" . (v:count1 + 1)<cr>gv=gv", { desc = "Move Up" })
-- Better line creation
-- map("n", "o", "o<ESC>", { desc = "Create line below and stay in normal mode" })
-- map("n", "O", "O<ESC>", { desc = "Create line above and stay in normal mode" })
map("n", "n", "nzz")
map("n", "N", "Nzz")
-- Insert mode mappings
map("i", "jj", "<ESC>", { desc = "Exit insert mode" })
map("i", "<C-d>", "<ESC>ddi", { desc = "Delete line" })
map("i", "<C-b>", "<ESC>^i", { desc = "Beginning of line" })
map("i", "<C-e>", "<End>", { desc = "End of line" })
-- Space as command key
-- map("n", "<Space>", ":", { desc = "Enter command mode" })
-- Move between buffers
map("n", "<S-TAB>", "<cmd>bprevious<cr>", { desc = "Prev Buffer" })
map("n", "<TAB>", "<cmd>bnext<cr>", { desc = "Next Buffer" })
-- map("n", "<leader>h", function()
-- require("nvchad.term").new({ pos = "sp", size = 0.4 })
-- end, { desc = "Terminal New horizontal term" })
map("t", "<C-x>", "<C-\\><C-N>", { desc = "Terminal Escape terminal mode" })
-- Keyboard users
vim.keymap.set("n", "<C-t>", function()
require("menu").open("default")
end, {})
-- mouse users + nvimtree users!
vim.keymap.set({ "n", "v" }, "<RightMouse>", function()
require("menu.utils").delete_old_menus()
vim.cmd.exec('"normal! \\<RightMouse>"')
-- clicked buf
local buf = vim.api.nvim_win_get_buf(vim.fn.getmousepos().winid)
local options = vim.bo[buf].ft == "NvimTree" and "nvimtree" or "default"
require("menu").open(options, { mouse = true })
end, {})
local nomap = vim.keymap.del
nomap({ "n", "i", "v" }, "<A-j>")
nomap("n", "<S-h>")
nomap("n", "<S-l>")