Files
nvim/lua/config/keymaps.lua
T
2026-06-28 20:15:04 +02:00

119 lines
7.2 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--[[
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣷⣦⣄⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠚⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠗⢀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣄⡉⠓⠦⣌⡙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⢋⣡⠴⠚⢉⣠⣤⣀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣶⣿⣿⣿⣿⣿⣷⣦⣄⡉⠓⠦⣌⡙⠻⢿⣿⣿⣿⣿⣿⣿⡿⠟⢋⣡⠴⠚⢉⣠⣴⣾⣿⣿⣿⣿⣿⣶⣤
⠀⠀⠀⠀⠀⠀⠀⠀⠐⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠓⠦⣌⡙⠻⠟⢋⣡⠴⠚⢉⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⠂
⠀⠀⠀⠀⢀⣠⣴⣆⡈⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠃⠘⢉⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢁⣰⣦⣄⡀
⠀⠀⠐⠾⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠷⠂
⠀⢸⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⡇
⠀⢸⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⡇
⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⡆⢰⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠃⠘⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⠿⠛⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⡇⢸⠿⠛⠉
__ _ _
/ _|___ ___| |_ __ _ ___| | __
| ||_ /____/ __| __/ _` |/ __| |/ /
| _/ /_____\__ \ || (_| | (__| <
|_|/___| |___/\__\__,_|\___|_|\_\
Neovim v0.12 configuration
(C) Frank Zechert 2026
]]
local map = vim.keymap.set
-- pressing ESC twices leaves terminal mode
map("t", "<Esc><Esc>", "<C-\\><C-n>", { desc = "Exit Terminal Mode" })
-- pressing ESC removes search highlights
map("n", "<Esc>", "<Cmd>nohlsearch<CR>", { desc = "Remove search result highlights" })
-- Smart buffer switch
-- switch to the alternative buffer ("#"), if not available, switch to the
-- previous buffer, if not possible, switch to the next buffer
local function smart_buffer_switch(current)
local alternative = vim.fn.bufnr("#")
local buffers = vim.fn.getbufinfo({ buflisted = 1 })
local current_index = nil
for index, buffer in ipairs(buffers) do
if buffer.bufnr == current then
current_index = index
break
end
end
-- try to switch to alternate buffer
if alternative > 0 and vim.fn.buflisted(alternative) == 1 and alternative ~= current then
vim.api.nvim_set_current_buf(alternative)
-- try to switch to previous buffer
elseif current_index and current_index > 1 then
vim.api.nvim_set_current_buf(buffers[current_index - 1].bufnr)
-- try to switch to next buffer
elseif current_index and current_index < #buffers then
vim.api.nvim_set_current_buf(buffers[current_index + 1].bufnr)
end
end
local function smart_buffer_delete()
local current = vim.api.nvim_get_current_buf()
smart_buffer_switch(current)
vim.cmd(":confirm bdelete " .. current)
end
local function smart_buffer_wipeout()
local current = vim.api.nvim_get_current_buf()
smart_buffer_switch(current)
vim.cmd(":confirm bwipeout " .. current)
end
local function delete_other_buffers()
local current = vim.api.nvim_get_current_buf()
for _, buffer in ipairs(vim.api.nvim_list_buffers()) do
if buffer ~= current and vim.bo[buffer].buflisted and not vim.bo[buffer].modified then
vim.api.nvim_buf_delete(buffer, {})
end
end
end
local function wipeout_other_buffers()
local current = vim.api.nvim_get_current_buf()
for _, buffer in ipairs(vim.api.nvim_list_buffers()) do
if buffer ~= current and vim.bo[buffer].buflisted and not vim.bo[buffer].modified then
vim.cmd("bwipeout " .. buffer)
end
end
end
map("n", "<leader>bd", smart_buffer_delete, { desc = "Close Current Buffer" })
map("n", "<leader>bw", smart_buffer_wipeout, { desc = "Wipeout Current Buffer" })
map("n", "<leader>bD", delete_other_buffers, { desc = "Close All Other Buffers" })
map("n", "<leader>bW", wipeout_other_buffers, { desc = "Wipeout All Other Buffers" })
-- Trouble Keybinds
-- open diagnostics window
map("n", "<leader>xd", [[<Cmd>Trouble diagnostics toggle focus=false filter.buf=0<CR>]], { desc = "Toggle diagnostic message for current buffer" })
map("n", "<leader>xD", [[<Cmd>Trouble diagnostics toggle focus=false<CR>]], { desc = "Toggle diagnostic message for project" })
map("n", "grt", [[<Cmd>Trouble symbols toggle focus=false<CR>]], { desc = "Open TreeSitter Symbols" })
map("n", "grs", [[<Cmd>Trouble lsp_document_symbols toggle focus=false<CR>]], { desc = "Open LSP Document Symbols", silent = true, noremap = true })
map("n", "grS", [[<Cmd>Trouble lsp_workspace_symbols toggle focus=false<CR>]], { desc = "Open LSP Workspace Symbols", silent = true, noremap = true })
map("n", "grD", [[<Cmd>Trouble lsp_declarations toggle<CR>]], { desc = "Show LSP Declarations", silent = true, noremap = true })
map("n", "grd", [[<Cmd>Trouble lsp_definitions toggle<CR>]], { desc = "Show LSP Definitions", silent = true, noremap = true })
map("n", "gri", [[<Cmd>Trouble lsp_implementations toggle<CR>]], { desc = "Show LSP Implementations", silent = true, noremap = true })
map("n", "grc", [[<Cmd>Trouble lsp_incoming_calls toggle<CR>]], { desc = "Show LSP incoming calls", silent = true, noremap = true })
map("n", "grC", [[<Cmd>Trouble lsp_outgoing_calls toggle<CR>]], { desc = "Show LSP outgoing calls", silent = true, noremap = true })
map("n", "grr", [[<Cmd>Trouble lsp_references toggle<CR>]], { desc = "Show LSP references", silent = true, noremap = true })
map("n", "<leader>xq", [[<Cmd>Trouble qflist toggle focus=false<CR>]], { desc = "Show Quickfix List" })
map("n", "<leader>xl", [[<Cmd>Trouble loclist toggle focus=false<CR>]], { desc = "Show Location List" })
map("n", "grn", vim.lsp.buf.rename, { desc = "Rename", silent = true, noremap = true })
map("n", "gra", vim.lsp.buf.code_action, { desc = "Action", silent = true, noremap = true })
map("n", "gl", vim.diagnostic.open_float, { desc = "Open Diagnostic Float" })