49 lines
2.3 KiB
Lua
49 lines
2.3 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 = 'Go to definition (built-in fallback)', silent = true })
|
|
|
|
map('n', 'gD', function()
|
|
-- Built-in: jump to declaration (global)
|
|
vim.cmd("normal! gD")
|
|
end, { desc = '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 = 'References (requires LSP)', silent = true })
|
|
map('n', 'gI', '<Nop>', { desc = '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 = 'Hover/Help (LSP or keywordprg fallback)', silent = true })
|
|
|
|
-- Diagnostic keymaps
|
|
map('n', '<leader>xx', vim.diagnostic.setloclist, { desc = 'Show buffer diagnostics in location list', silent = true })
|
|
map('n', '<leader>xX', vim.diagnostic.setqflist, { desc = 'Show all diagnostics in quickfix', silent = true })
|
|
map('n', '<leader>xe', function()
|
|
vim.diagnostic.setloclist({ severity = vim.diagnostic.severity.ERROR })
|
|
end, { desc = 'Show buffer errors in location list', silent = true })
|
|
map('n', '<leader>xE', function()
|
|
vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR })
|
|
end, { desc = 'Show all errors in quickfix', silent = true })
|
|
map('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic', silent = true })
|
|
map('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic', silent = true })
|
|
map('n', '<leader>xd', vim.diagnostic.open_float, { desc = 'Show diagnostic under cursor', silent = true })
|