nvim-config/lua/core/keymaps.lua

81 lines
2.6 KiB
Lua

local map = require("helpers.keys").map
-- Quick access to some common actions
map("n", "<leader>fw", "<cmd>w<cr>", "Write")
map("n", "<leader>fa", "<cmd>wa<cr>", "Write all")
map("n", "<leader>qq", "<cmd>q<cr>", "Quit")
map("n", "<leader>qa", "<cmd>qa!<cr>", "Quit all")
map("n", "<leader>dw", "<cmd>close<cr>", "Window")
map("n", ";", "A;<Esc>", "places \";\" at end of line")
-- Diagnostic keymaps
map('n', 'gx', vim.diagnostic.open_float, "Show diagnostics under cursor")
-- Easier access to beginning and end of lines
map("n", "<M-h>", "^", "Go to beginning of line")
map("n", "<M-l>", "$", "Go to end of line")
-- Better window navigation
map("n", "<C-h>", "<C-w><C-h>", "Navigate windows to the left")
map("n", "<C-j>", "<C-w><C-j>", "Navigate windows down")
map("n", "<C-k>", "<C-w><C-k>", "Navigate windows up")
map("n", "<C-l>", "<C-w><C-l>", "Navigate windows to the right")
-- Move with shift-arrows
map("n", "<S-Left>", "<C-w><S-h>", "Move window to the left")
map("n", "<S-Down>", "<C-w><S-j>", "Move window down")
map("n", "<S-Up>", "<C-w><S-k>", "Move window up")
map("n", "<S-Right>", "<C-w><S-l>", "Move window to the right")
-- Resize with arrows
map("n", "<C-Up>", ":resize +2<CR>")
map("n", "<C-Down>", ":resize -2<CR>")
map("n", "<C-Left>", ":vertical resize +2<CR>")
map("n", "<C-Right>", ":vertical resize -2<CR>")
-- Deleting buffers
local buffers = require("helpers.buffers")
map("n", "<leader>db", buffers.delete_this, "Current buffer")
map("n", "<leader>do", buffers.delete_others, "Other buffers")
map("n", "<leader>da", buffers.delete_all, "All buffers")
-- Navigate buffers
map("n", "<S-l>", ":bnext<CR>")
map("n", "<S-h>", ":bprevious<CR>")
-- Stay in indent mode
map("v", "<", "<gv")
map("v", ">", ">gv")
-- Switch between light and dark modes
map("n", "<leader>ut", function()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
end, "Toggle between light and dark themes")
-- Clear after search
map("n", "<leader>ur", "<cmd>nohl<cr>", "Clear highlights")
-- Open config
map("n", "<leader>Nc", "<cmd>n ~/.config/nvim/init.lua<cr>", "Open Config")
-- ToggleTerm config
local Terminal = require('toggleterm.terminal').Terminal
local lazygit = Terminal:new({cmd = "lazygit", hidden = true, direction='tab'})
function _lazygit_toggle()
lazygit:toggle()
end
map("n", "<leader>gg", "<cmd>lua _lazygit_toggle()<cr>", "open lazygit")
-- Bacon config
local bacon = Terminal:new({cmd = "bacon --job clippy", hidden = true, direction='tab'})
function _bacon_toggle()
bacon:toggle()
end
map("n", "<leader>h", "<cmd>lua _bacon_toggle()<cr>", "open bacon")