nix-infra/modules/home/nvim/lua/config/keymaps.lua

91 lines
3.9 KiB
Lua
Raw Normal View History

2024-03-24 18:02:32 +00:00
-- 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
2024-03-24 18:02:21 +00:00
2024-03-24 18:02:32 +00:00
-- This file is automatically loaded by lazyvim.config.init
local Util = require("lazyvim.util")
local map = vim.keymap.set
2024-03-24 18:02:21 +00:00
-- Move to window using the <ctrl> hjkl keys
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })
-- Resize window using <ctrl> arrow keys
map("n", "<C-Up>", "<cmd>resize +2<cr>", { desc = "Increase window height" })
map("n", "<C-Down>", "<cmd>resize -2<cr>", { desc = "Decrease window height" })
map("n", "<C-Left>", "<cmd>vertical resize -2<cr>", { desc = "Decrease window width" })
map("n", "<C-Right>", "<cmd>vertical resize +2<cr>", { desc = "Increase window width" })
-- Move Lines
map("n", "<A-j>", "<cmd>m .+1<cr>==", { desc = "Move down" })
map("n", "<A-k>", "<cmd>m .-2<cr>==", { desc = "Move up" })
map("i", "<A-j>", "<esc><cmd>m .+1<cr>==gi", { desc = "Move down" })
map("i", "<A-k>", "<esc><cmd>m .-2<cr>==gi", { desc = "Move up" })
map("v", "<A-j>", ":m '>+1<cr>gv=gv", { desc = "Move down" })
map("v", "<A-k>", ":m '<-2<cr>gv=gv", { desc = "Move up" })
-- buffers
map("n", "<S-h>", "<cmd>bprevious<cr>", { desc = "Prev buffer" })
map("n", "<S-l>", "<cmd>bnext<cr>", { desc = "Next buffer" })
2024-03-24 18:02:32 +00:00
map("n", "<leader>bb", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
map("n", "<leader>`", "<cmd>e #<cr>", { desc = "Switch to Other Buffer" })
2024-03-24 18:02:21 +00:00
-- save file
map({ "i", "x", "n", "s" }, "<C-s>", "<cmd>w<cr><esc>", { desc = "Save file" })
-- new file
map("n", "<leader>fn", "<cmd>enew<cr>", { desc = "New File" })
map("n", "<leader>xl", "<cmd>lopen<cr>", { desc = "Location List" })
map("n", "<leader>xq", "<cmd>copen<cr>", { desc = "Quickfix List" })
2024-03-24 18:02:32 +00:00
if not Util.has("trouble.nvim") then
map("n", "[q", vim.cmd.cprev, { desc = "Previous quickfix" })
map("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" })
end
-- diagnostic
local diagnostic_goto = function(next, severity)
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
severity = severity and vim.diagnostic.severity[severity] or nil
return function()
go({ severity = severity })
end
end
map("n", "<leader>cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
map("n", ")d", diagnostic_goto(true), { desc = "Next Diagnostic" })
map("n", "(d", diagnostic_goto(false), { desc = "Prev Diagnostic" })
map("n", ")e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" })
map("n", "(e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" })
map("n", ")w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" })
map("n", "(w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" })
-- windows
2024-03-24 18:02:21 +00:00
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })
map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
2024-03-24 18:02:32 +00:00
map("n", "<leader>.", "<C-W>v", { desc = "Split window right", remap = true })
2024-03-24 18:02:21 +00:00
-- tabs
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
map("n", "<leader><tab>f", "<cmd>tabfirst<cr>", { desc = "First Tab" })
map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
2024-03-24 18:02:32 +00:00
map("n", "<leader><tab>n", "<cmd>tabnext<cr>", { desc = "Next Tab" })
2024-03-24 18:02:21 +00:00
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
2024-03-24 18:02:32 +00:00
map("n", "<leader><tab>p", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })
-- Unmapping some lazyvim default keymaps
local unmap = vim.keymap.del
unmap("n", "[b")
unmap("n", "]b")
unmap("n", "<leader>/")
unmap("n", "<leader>|")
unmap("n", "<leader>L")
unmap("n", "<leader>`")
unmap("n", "<leader><tab>[")
unmap("n", "<leader><tab>]")