update
This commit is contained in:
parent
8bde5cc4d3
commit
02df315571
|
|
@ -1,42 +1,35 @@
|
||||||
-- Non-plugin and global helper keymaps
|
-- 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
|
local map = vim.keymap.set
|
||||||
local opts = { noremap = true, silent = true }
|
|
||||||
|
|
||||||
-- LSP-aware helpers with graceful fallback to built-ins
|
-- Fallback navigation keymaps for non-LSP buffers
|
||||||
local function lsp_has(bufnr, capability)
|
-- When LSP attaches, buffer-local keymaps in lsp.lua override these
|
||||||
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
|
|
||||||
if client.server_capabilities[capability] then return true end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local function lsp_or_builtin(bufnr, capability, lsp_fn, builtin_normal)
|
|
||||||
if lsp_has(bufnr, capability) then
|
|
||||||
lsp_fn()
|
|
||||||
else
|
|
||||||
vim.cmd("normal! " .. builtin_normal)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Global LSP-keymaps with fallback so they work reliably
|
|
||||||
map('n', 'gd', function()
|
map('n', 'gd', function()
|
||||||
lsp_or_builtin(0, 'definitionProvider', vim.lsp.buf.definition, 'gd')
|
-- Built-in: jump to definition via tags or included files
|
||||||
end, { desc = 'Go to definition (LSP or built-in)' })
|
vim.cmd("normal! gd")
|
||||||
|
end, { desc = 'Go to definition (built-in fallback)', silent = true })
|
||||||
map('n', 'gr', function()
|
|
||||||
if lsp_has(0, 'referencesProvider') then vim.lsp.buf.references() end
|
|
||||||
end, { desc = 'References (LSP)', silent = true })
|
|
||||||
|
|
||||||
map('n', 'gD', function()
|
map('n', 'gD', function()
|
||||||
lsp_or_builtin(0, 'declarationProvider', vim.lsp.buf.declaration, 'gD')
|
-- Built-in: jump to declaration (global)
|
||||||
end, { desc = 'Go to declaration (LSP or built-in)' })
|
vim.cmd("normal! gD")
|
||||||
|
end, { desc = 'Go to declaration (built-in fallback)', silent = true })
|
||||||
|
|
||||||
map('n', 'gI', function()
|
-- LSP-only keymaps (no useful fallback for these in non-LSP contexts)
|
||||||
if lsp_has(0, 'implementationProvider') then vim.lsp.buf.implementation() end
|
map('n', 'gr', '<Nop>', { desc = 'References (requires LSP)', silent = true })
|
||||||
end, { desc = 'Go to implementation (LSP)', silent = true })
|
map('n', 'gI', '<Nop>', { desc = 'Implementation (requires LSP)', silent = true })
|
||||||
|
|
||||||
|
-- K: Hover/Help with sensible fallback
|
||||||
map('n', 'K', function()
|
map('n', 'K', function()
|
||||||
if lsp_has(0, 'hoverProvider') then vim.lsp.buf.hover() end
|
-- Built-in K uses 'keywordprg' (defaults to 'man' for shell scripts, etc.)
|
||||||
end, { desc = 'Hover (LSP)', silent = true })
|
-- LSP buffers override this with vim.lsp.buf.hover() in lsp.lua
|
||||||
|
if vim.bo.keywordprg ~= '' then
|
||||||
return {}
|
vim.cmd("normal! K")
|
||||||
|
end
|
||||||
|
end, { desc = 'Hover/Help (LSP or keywordprg fallback)', silent = true })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue