-- 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', '', { desc = 'LSP: References (requires LSP)', silent = true }) map('n', 'gI', '', { 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', 'co', 'copen', { desc = 'Quickfix: Open', silent = true }) map('n', 'cc', 'cclose', { desc = 'Quickfix: Close', silent = true }) map('n', 'lo', 'lopen', { desc = 'Location list: Open', silent = true }) map('n', 'lc', 'lclose', { desc = 'Location list: Close', silent = true }) -- Diagnostic keymaps map('n', 'xx', vim.diagnostic.setloclist, { desc = 'Diagnostics: Buffer diagnostics (location list)', silent = true }) map('n', 'xX', vim.diagnostic.setqflist, { desc = 'Diagnostics: All diagnostics (quickfix)', silent = true }) map('n', 'xe', function() vim.diagnostic.setloclist({ severity = vim.diagnostic.severity.ERROR }) end, { desc = 'Diagnostics: Buffer errors (location list)', silent = true }) map('n', 'xE', function() vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) end, { desc = 'Diagnostics: All errors (quickfix)', silent = true }) map('n', '[d', vim.diagnostic.goto_prev, { desc = 'Diagnostics: Previous diagnostic', silent = true }) map('n', ']d', vim.diagnostic.goto_next, { desc = 'Diagnostics: Next diagnostic', silent = true }) map('n', 'xd', vim.diagnostic.open_float, { desc = 'Diagnostics: Show diagnostic under cursor', silent = true }) map('n', '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', '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', 'hi', function() require('utils').show_highlight_info() end, { desc = 'Debug: Show highlight group and color under cursor', silent = true })