spectre and lsp keybindings

This commit is contained in:
Walter Jenkins 2025-11-26 09:46:14 -06:00
parent 4564d7093e
commit eea5afaa74
5 changed files with 134 additions and 205 deletions

59
.session.vim Normal file
View File

@ -0,0 +1,59 @@
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/.config/nvim
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
set shortmess=aoOA
else
set shortmess=aoO
endif
badd +1 doc/kickstart.txt
argglobal
%argdel
edit doc/kickstart.txt
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
argglobal
setlocal foldmethod=expr
setlocal foldexpr=nvim_treesitter#foldexpr()
setlocal foldmarker={{{,}}}
setlocal foldignore=#
setlocal foldlevel=99
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldenable
let s:l = 1 - ((0 * winheight(0) + 24) / 48)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 1
normal! 0
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :

View File

@ -33,7 +33,6 @@ local theme_module = themes[env_var_nvim_theme] or themes[default_color_scheme]
require('lazy').setup({ require('lazy').setup({
require(theme_module), require(theme_module),
require 'core.ui', require 'core.ui',
-- Load mason early so tools are ready for LSP configs -- Load mason early so tools are ready for LSP configs
require 'plugins.mason', require 'plugins.mason',
@ -54,6 +53,7 @@ require('lazy').setup({
require 'plugins.lazygit', require 'plugins.lazygit',
require 'plugins.aerial', require 'plugins.aerial',
require 'plugins.misc', require 'plugins.misc',
require 'plugins.snack',
-- LSP & companions -- LSP & companions
require 'plugins.autocompletion', require 'plugins.autocompletion',
@ -68,6 +68,9 @@ require('lazy').setup({
-- Debugging / DB (as you had) -- Debugging / DB (as you had)
require 'plugins.debug', require 'plugins.debug',
require 'plugins.database', require 'plugins.database',
require 'plugins.lsp-keymaps',
require 'plugins.spectre',
}, { }, {
ui = { ui = {
icons = vim.g.have_nerd_font and {} or { icons = vim.g.have_nerd_font and {} or {

View File

@ -1,208 +1,51 @@
local M = {} -- lua/plugins/lsp-keymaps.lua
return {
-- Attach to the existing LSP config plugin
'neovim/nvim-lspconfig',
M._keys = nil -- We just need this to run once; inside we create an LspAttach autocmd
event = 'VeryLazy',
---@return table config = function()
function M.get() -- Only define the autocmd once
if M._keys then vim.api.nvim_create_augroup('UserLspKeymaps', { clear = true })
return M._keys
vim.api.nvim_create_autocmd('LspAttach', {
group = 'UserLspKeymaps',
callback = function(ev)
local bufnr = ev.buf
local opts = function(extra)
return vim.tbl_extend('force', { buffer = bufnr, silent = true, noremap = true }, extra or {})
end end
-- Standard LSP Keybindings (No LazyVim) -- Core LSP maps
M._keys = { vim.keymap.set('n', '<leader>cl', '<cmd>LspInfo<CR>', opts { desc = 'LSP Info' })
{ '<leader>cl', '<cmd>LspInfo<cr>', desc = 'LSP Info' },
{ 'gd', vim.lsp.buf.definition, desc = 'Go to Definition' }, vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts { desc = 'Go to Definition' })
{ 'gr', vim.lsp.buf.references, desc = 'References' }, vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts { desc = 'References' })
{ 'gI', vim.lsp.buf.implementation, desc = 'Go to Implementation' }, vim.keymap.set('n', 'gI', vim.lsp.buf.implementation, opts { desc = 'Go to Implementation' })
{ 'gy', vim.lsp.buf.type_definition, desc = 'Go to Type Definition' }, vim.keymap.set('n', 'gy', vim.lsp.buf.type_definition, opts { desc = 'Go to Type Definition' })
{ 'gD', vim.lsp.buf.declaration, desc = 'Go to Declaration' }, vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts { desc = 'Go to Declaration' })
{ 'gK', vim.lsp.buf.signature_help, desc = 'Signature Help' }, vim.keymap.set('n', 'gK', vim.lsp.buf.signature_help, opts { desc = 'Signature Help' })
{ '<C-k>', vim.lsp.buf.signature_help, mode = 'i', desc = 'Signature Help' },
{ '<leader>ca', vim.lsp.buf.code_action, desc = 'Code Action', mode = { 'n', 'v' } }, vim.keymap.set('i', '<C-k>', vim.lsp.buf.signature_help, opts { desc = 'Signature Help' })
{ '<leader>cr', vim.lsp.buf.rename, desc = 'Rename' },
{ vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts { desc = 'Code Action' })
'<leader>cR',
function() -- Rename symbol
if require 'snacks.rename' then vim.keymap.set('n', '<leader>cr', vim.lsp.buf.rename, opts { desc = 'Rename' })
require('snacks.rename').rename_file()
-- Rename file via Snacks, but **safely**
vim.keymap.set('n', '<leader>cR', function()
local ok, snacks = pcall(require, 'snacks')
if ok and snacks.rename and snacks.rename.rename_file then
snacks.rename.rename_file()
else else
print 'Snacks rename not available' print 'Snacks rename not available'
end end
end, opts { desc = 'Rename File' })
end, end,
desc = 'Rename File', })
mode = { 'n' }, end,
has = { 'workspace/didRenameFiles', 'workspace/willRenameFiles' }, }
},
{ '<leader>cr', vim.lsp.buf.rename, desc = 'Rename', has = 'rename' },
}
return M._keys
end
---@param buffer number
function M.on_attach(_, buffer)
for _, key in pairs(M.get()) do
vim.keymap.set(key.mode or 'n', key[1], key[2], { buffer = buffer, desc = key.desc, silent = true })
end
end
return M
-- local M = {}
--
-- ---@type LazyKeysLspSpec[]|nil
-- M._keys = nil
--
-- ---@alias LazyKeysLspSpec LazyKeysSpec|{has?:string|string[], cond?:fun():boolean}
-- ---@alias LazyKeysLsp LazyKeys|{has?:string|string[], cond?:fun():boolean}
--
-- ---@return LazyKeysLspSpec[]
-- function M.get()
-- if M._keys then
-- return M._keys
-- end
-- -- stylua: ignore
-- M._keys = {
-- { "<leader>cl", "<cmd>LspInfo<cr>", desc = "LSP Info" },
-- { "gd", vim.lsp.buf.definition, desc = "Go to Definition", has = "definition" },
-- { "gr", vim.lsp.buf.references, desc = "References", nowait = true },
-- { "gI", vim.lsp.buf.implementation, desc = "Go to Implementation" },
-- { "gy", vim.lsp.buf.type_definition, desc = "Go to Type Definition" },
-- { "gD", vim.lsp.buf.declaration, desc = "Go to Declaration" },
-- { "K", function() return vim.lsp.buf.hover() end, desc = "Hover" },
-- { "gK", function() return vim.lsp.buf.signature_help() end, desc = "Signature Help", has = "signatureHelp" },
-- { "<C-k>", function() return vim.lsp.buf.signature_help() end, mode = "i", desc = "Signature Help", has = "signatureHelp" },
-- { "<leader>ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" },
-- { "<leader>cc", vim.lsp.codelens.run, desc = "Run CodeLens", mode = { "n", "v" }, has = "codeLens" },
-- { "<leader>cC", vim.lsp.codelens.refresh, desc = "Refresh & Display CodeLens", mode = { "n" }, has = "codeLens" },
-- {
-- "<leader>cR",
-- function()
-- if require("snacks.rename") then
-- require("snacks.rename").rename_file()
-- else
-- print("Snacks rename not available")
-- end
-- end,
-- desc = "Rename File",
-- mode = { "n" },
-- has = { "workspace/didRenameFiles", "workspace/willRenameFiles" }
-- },
-- { "<leader>cr", vim.lsp.buf.rename, desc = "Rename", has = "rename" },
-- {
-- "<leader>cA",
-- function()
-- if require("lazyvim.lsp.action") then
-- require("lazyvim.lsp.action").source()
-- else
-- print("LazyVim LSP action not available")
-- end
-- end,
-- desc = "Source Action",
-- has = "codeAction"
-- },
-- {
-- "]]",
-- function()
-- if require("snacks.words") then
-- require("snacks.words").jump(vim.v.count1)
-- end
-- end,
-- has = "documentHighlight",
-- desc = "Next Reference",
-- cond = function() return require("snacks.words").is_enabled() end
-- },
-- {
-- "[[",
-- function()
-- if require("snacks.words") then
-- require("snacks.words").jump(-vim.v.count1)
-- end
-- end,
-- has = "documentHighlight",
-- desc = "Previous Reference",
-- cond = function() return require("snacks.words").is_enabled() end
-- },
-- {
-- "<A-n>",
-- function()
-- if require("snacks.words") then
-- require("snacks.words").jump(vim.v.count1, true)
-- end
-- end,
-- has = "documentHighlight",
-- desc = "Next Reference",
-- cond = function() return require("snacks.words").is_enabled() end
-- },
-- {
-- "<A-p>",
-- function()
-- if require("snacks.words") then
-- require("snacks.words").jump(-vim.v.count1, true)
-- end
-- end,
-- has = "documentHighlight",
-- desc = "Previous Reference",
-- cond = function() return require("snacks.words").is_enabled() end
-- },
-- }
--
-- return M._keys
-- end
--
-- ---@param buffer number
-- ---@param method string|string[]
-- function M.has(buffer, method)
-- if type(method) == 'table' then
-- for _, m in ipairs(method) do
-- if M.has(buffer, m) then
-- return true
-- end
-- end
-- return false
-- end
-- method = method:find '/' and method or 'textDocument/' .. method
-- local clients = vim.lsp.get_active_clients { bufnr = buffer }
-- for _, client in ipairs(clients) do
-- if client.supports_method(method) then
-- return true
-- end
-- end
-- return false
-- end
--
-- ---@return LazyKeysLsp[]
-- function M.resolve(buffer)
-- local Keys = require 'lazy.core.handler.keys'
-- if not Keys.resolve then
-- return {}
-- end
-- local spec = vim.tbl_extend('force', {}, M.get())
-- local opts = require 'nvim-lspconfig'
-- local clients = vim.lsp.get_active_clients { bufnr = buffer }
-- for _, client in ipairs(clients) do
-- local maps = opts.servers and opts.servers[client.name] and opts.servers[client.name].keys or {}
-- vim.list_extend(spec, maps)
-- end
-- return Keys.resolve(spec)
-- end
--
-- function M.on_attach(_, buffer)
-- local Keys = require 'lazy.core.handler.keys'
-- local keymaps = M.resolve(buffer)
--
-- for _, keys in pairs(keymaps) do
-- local has = not keys.has or M.has(buffer, keys.has)
-- local cond = not (keys.cond == false or ((type(keys.cond) == 'function') and not keys.cond()))
--
-- if has and cond then
-- local opts = Keys.opts(keys)
-- opts.cond = nil
-- opts.has = nil
-- opts.silent = opts.silent ~= false
-- opts.buffer = buffer
-- vim.keymap.set(keys.mode or 'n', keys.lhs, keys.rhs, opts)
-- end
-- end
-- end
--
-- return M

View File

@ -20,9 +20,9 @@ return {
image = { image = {
enabled = true, -- force enable even if terminal isn't fully supported enabled = true, -- force enable even if terminal isn't fully supported
backend = "magick", -- fallback backend for images backend = "magick", -- fallback backend for images
diagnostics = true, -- keep this on so you can see setup issues diagnostics = false, -- keep this on so you can see setup issues
auto_preview = false, -- if you dont want inline previews on hover auto_preview = false, -- if you dont want inline previews on hover
view = "image", -- can be "image", "ascii", or "none" view = "ascii", -- can be "image", "ascii", or "none"
max_height = 30, -- in rows max_height = 30, -- in rows
max_width = 50, -- in columns max_width = 50, -- in columns
use_dither = false, -- optional: enable dithered rendering use_dither = false, -- optional: enable dithered rendering

24
lua/plugins/spectre.lua Normal file
View File

@ -0,0 +1,24 @@
return {
-- other plugins …
-- nvim-spectre
{
"nvim-pack/nvim-spectre",
dependencies = { "nvim-lua/plenary.nvim" },
-- optionally configure lazy loading:
-- lazy = true, -- default
-- or set events/commands/ft if desired
-- you can also provide setup/options here if you want:
config = function()
require("spectre").setup({
-- your config overrides, or just omit for defaults
})
-- example keymap
vim.keymap.set('n', '<leader>S', '<cmd>lua require("spectre").toggle()<CR>', { desc = "Toggle Spectre" })
end,
},
-- other plugins …
}