Files
nvim/lua/conf/binds.lua
2025-08-10 13:10:05 -04:00

66 lines
2.2 KiB
Lua

local map, lz = core.misc.map, core.misc.lz
--- feed keys as userinput
---@param keys string keys
local function feedkeys(keys)
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(keys, true, false, true),
"n", true)
end
-- vim binds
vim.g.mapleader = " " -- set leader key
map("x", "<leader>p", [["_dP]], { desc = "Greatest remap of all time." })
map("n", "<esc>", "<cmd>noh<Bar>:ec<CR>", { desc = "Clear search." })
map("n", "<leader>a", lz "<cmd>e #<CR>zz", { desc = "swap to alt file" })
-- the cursor STAYS IN THE MIDDLE
map("n", "<S-j>", lz "mzJ`z<cmd>delm z<CR>") -- when combining lines
map("n", "n", lz "nzzzv") -- when searching
map("n", "N", lz "Nzzzv")
map("n", "<C-d>", lz "<C-d>zz") -- half page jumping
map("n", "<C-u>", lz "<C-u>zz")
map("n", "<C-o>", lz "<C-o>zz") -- jump history
map("n", "<C-i>", lz "<C-i>zz")
-- trigger completion menu
-- (stolen from https://gist.github.com/MariaSolOs/2e44a86f569323c478e5a078d0cf98cc)
map("i", "<C-n>", function()
-- if the completion menu is already visible just go to the next item
if vim.fn.pumvisible() ~= 0 then
feedkeys("<C-n>")
else
if #vim.lsp.get_clients({ bufnr = 0 }) > 0 then
vim.lsp.completion.get()
else
if vim.bo.omnifunc == "" then
feedkeys("<C-x><C-n>")
else
feedkeys("<C-x><C-o>")
end
end
end
end, { desc = "Trigger/select next completion" })
map("i", "<C-s>", "<C-x><C-s>", { desc = "Trigger spell completion" })
map("n", "<C-s>", lz "<cmd>se spell<CR>ea<C-x><C-s><cmd>se nospell<CR>", { desc = "Trigger spell completion" })
-- quickfix
map("n", "<M-j>", "<cmd>cnext<CR>", { desc = "qf next" })
map("n", "<M-k>", "<cmd>cprev<CR>", { desc = "qf prev" })
map("n", "<M-c>", "<cmd>cclose<CR>", { desc = "qf close" })
map("n", "<M-x>", "<cmd>cope<CR>", { desc = "qf open" })
-- man pages
map("n", "<C-k>", "<cmd>Man<CR>")
-- okay this is gonna sound crazy, but I like emacs binds for editing when I'm
-- stuck without modal editing like in command mode.
map("c", "<C-a>", function() feedkeys("<Home>") end)
map("c", "<C-e>", function() feedkeys("<End>") end)
map("c", "<C-d>", function() feedkeys("<Del>") end)
-- execute line/block
map("n", "<leader>x", ":.lua<CR>")
map("x", "<leader>x", ":lua<CR>")