88 lines
3.8 KiB
Lua
88 lines
3.8 KiB
Lua
-- Non-plugin and global helper keymaps
|
|
--
|
|
-- NOTE: LSP keymaps are primarily handled in lua/plugins/lsp.lua via LspAttach.
|
|
-- Buffer-local keymaps set there take precedence over these global fallbacks.
|
|
--
|
|
-- These global keymaps provide fallback behavior for buffers without LSP attached,
|
|
-- ensuring that common navigation keys still work with built-in Vim functionality
|
|
-- (e.g., ctags, included files, man pages).
|
|
|
|
local map = vim.keymap.set
|
|
|
|
-- Fallback navigation keymaps for non-LSP buffers
|
|
-- When LSP attaches, buffer-local keymaps in lsp.lua override these
|
|
map('n', 'gd', function()
|
|
-- Built-in: jump to definition via tags or included files
|
|
vim.cmd("normal! gd")
|
|
end, { desc = 'Vim: Go to definition (built-in fallback)', silent = true })
|
|
|
|
map('n', 'gD', function()
|
|
-- Built-in: jump to declaration (global)
|
|
vim.cmd("normal! gD")
|
|
end, { desc = 'Vim: Go to declaration (built-in fallback)', silent = true })
|
|
|
|
-- LSP-only keymaps (no useful fallback for these in non-LSP contexts)
|
|
map('n', 'gr', '<Nop>', { desc = 'LSP: References (requires LSP)', silent = true })
|
|
map('n', 'gI', '<Nop>', { desc = 'LSP: Implementation (requires LSP)', silent = true })
|
|
|
|
-- K: Hover/Help with sensible fallback
|
|
map('n', 'K', function()
|
|
-- Built-in K uses 'keywordprg' (defaults to 'man' for shell scripts, etc.)
|
|
-- LSP buffers override this with vim.lsp.buf.hover() in lsp.lua
|
|
if vim.bo.keywordprg ~= '' then
|
|
vim.cmd("normal! K")
|
|
end
|
|
end, { desc = 'Vim: Hover/Help (keywordprg fallback)', silent = true })
|
|
|
|
-- Quickfix and Location list keymaps
|
|
map('n', '<leader>co', '<cmd>copen<cr>', { desc = 'Quickfix: Open', silent = true })
|
|
map('n', '<leader>cc', '<cmd>cclose<cr>', { desc = 'Quickfix: Close', silent = true })
|
|
map('n', '<leader>lo', '<cmd>lopen<cr>', { desc = 'Location list: Open', silent = true })
|
|
map('n', '<leader>lc', '<cmd>lclose<cr>', { desc = 'Location list: Close', silent = true })
|
|
|
|
-- Diagnostic keymaps
|
|
map('n', '<leader>xx', vim.diagnostic.setloclist, { desc = 'Diagnostics: Buffer diagnostics (location list)', silent = true })
|
|
map('n', '<leader>xX', vim.diagnostic.setqflist, { desc = 'Diagnostics: All diagnostics (quickfix)', silent = true })
|
|
map('n', '<leader>xe', function()
|
|
vim.diagnostic.setloclist({ severity = vim.diagnostic.severity.ERROR })
|
|
end, { desc = 'Diagnostics: Buffer errors (location list)', silent = true })
|
|
map('n', '<leader>xE', function()
|
|
vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR })
|
|
end, { desc = 'Diagnostics: All errors (quickfix)', silent = true })
|
|
map('n', '[d', function()
|
|
vim.diagnostic.goto_prev({ float = false })
|
|
end, { desc = 'Diagnostics: Previous diagnostic', silent = true })
|
|
map('n', ']d', function()
|
|
vim.diagnostic.goto_next({ float = false })
|
|
end, { desc = 'Diagnostics: Next diagnostic', silent = true })
|
|
map('n', '<leader>xd', function()
|
|
pcall(vim.diagnostic.open_float)
|
|
end, { desc = 'Diagnostics: Show diagnostic under cursor', silent = true })
|
|
map('n', '<leader>xt', function()
|
|
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
|
end, { desc = 'Diagnostics: Toggle display', silent = true })
|
|
|
|
-- Git: Modified, deleted, and untracked files to quickfix
|
|
map('n', '<leader>gg', function()
|
|
local utils = require('utils')
|
|
local qf_list = utils.git_changed_files()
|
|
if qf_list then
|
|
vim.fn.setqflist(qf_list, 'r')
|
|
vim.cmd('copen')
|
|
end
|
|
end, { desc = 'Git: Changed files to quickfix (with status)', silent = true })
|
|
|
|
-- Debug: Show highlight group and color under cursor
|
|
map('n', '<leader>hi', function()
|
|
require('utils').show_highlight_info()
|
|
end, { desc = 'Debug: Show highlight group and color under cursor', silent = true })
|
|
|
|
-- UI: Toggle background (light/dark)
|
|
map('n', '<leader>bg', function()
|
|
if vim.o.background == 'dark' then
|
|
vim.o.background = 'light'
|
|
else
|
|
vim.o.background = 'dark'
|
|
end
|
|
end, { desc = 'UI: Toggle background (light/dark)', silent = true })
|