From f1cc5ca1ba1ed588f4c658f1e3ec091c1548a3e1 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 12 Mar 2026 15:42:20 -0400 Subject: [PATCH] feat: improve inverse search cmd --- config/nvim/lua/config/lsp.lua | 37 +++++++++++++++++---------------- config/nvim/lua/plugins/dev.lua | 11 +++++----- config/nvim/lua/plugins/fzf.lua | 3 ++- config/nvim/plugin/options.lua | 5 +++-- home/modules/packages.nix | 2 +- scripts/nvim-inverse-search | 12 +++++++++++ 6 files changed, 42 insertions(+), 28 deletions(-) create mode 100755 scripts/nvim-inverse-search diff --git a/config/nvim/lua/config/lsp.lua b/config/nvim/lua/config/lsp.lua index 46aa994..ca5020d 100644 --- a/config/nvim/lua/config/lsp.lua +++ b/config/nvim/lua/config/lsp.lua @@ -2,65 +2,66 @@ local M = {} local Methods = vim.lsp.protocol.Methods +local function fzf_or(fzf_cmd, fallback) + return function() + if pcall(require, 'fzf-lua') then + vim.cmd('FzfLua ' .. fzf_cmd) + else + fallback() + end + end +end + function M.on_attach(client, bufnr) if client:supports_method(Methods.textDocument_hover) then vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr }) end - local ok, _ = pcall(require, 'fzf-lua') - local mappings = { { Methods.textDocument_codeAction, 'gra', - ok and 'FzfLua lsp_code_actions' - or vim.lsp.buf.code_action, + fzf_or('lsp_code_actions', vim.lsp.buf.code_action), }, { Methods.textDocument_declaration, 'gD', - ok and 'FzfLua lsp_declarations' - or vim.lsp.buf.declaration, + fzf_or('lsp_declarations', vim.lsp.buf.declaration), }, { Methods.textDocument_definition, 'gd', - ok and 'FzfLua lsp_definitions' or vim.lsp.buf.definition, + fzf_or('lsp_definitions', vim.lsp.buf.definition), }, { Methods.textDocument_implementation, 'gri', - ok and 'FzfLua lsp_implementations' - or vim.lsp.buf.implementation, + fzf_or('lsp_implementations', vim.lsp.buf.implementation), }, { Methods.textDocument_references, 'grr', - ok and 'FzfLua lsp_references' or vim.lsp.buf.references, + fzf_or('lsp_references', vim.lsp.buf.references), }, { Methods.textDocument_typeDefinition, 'grt', - ok and 'FzfLua lsp_typedefs' - or vim.lsp.buf.type_definition, + fzf_or('lsp_typedefs', vim.lsp.buf.type_definition), }, { Methods.textDocument_documentSymbol, 'gs', - ok and 'FzfLua lsp_document_symbols' - or vim.lsp.buf.document_symbol, + fzf_or('lsp_document_symbols', vim.lsp.buf.document_symbol), }, { Methods.workspace_diagnostic, 'gw', - ok and 'FzfLua lsp_workspace_diagnostics' - or vim.diagnostic.setqflist, + fzf_or('lsp_workspace_diagnostics', vim.diagnostic.setqflist), }, { Methods.workspace_symbol, 'gS', - ok and 'FzfLua lsp_workspace_symbols' - or vim.lsp.buf.workspace_symbol, + fzf_or('lsp_workspace_symbols', vim.lsp.buf.workspace_symbol), }, } diff --git a/config/nvim/lua/plugins/dev.lua b/config/nvim/lua/plugins/dev.lua index 487b8be..2250f2b 100644 --- a/config/nvim/lua/plugins/dev.lua +++ b/config/nvim/lua/plugins/dev.lua @@ -161,10 +161,7 @@ return { end end end, - group = vim.api.nvim_create_augroup( - 'AOil', - { clear = true } - ), + group = vim.api.nvim_create_augroup('AOil', { clear = true }), }) end, event = 'DeferredUIEnter', @@ -335,7 +332,7 @@ return { vim.filetype.add({ extension = { puml = 'plantuml', pu = 'plantuml' }, }) - vim.fn.serverstart('/tmp/nvim-preview.sock') + vim.api.nvim_create_autocmd('User', { pattern = 'PreviewCompileSuccess', callback = function(args) @@ -369,7 +366,9 @@ return { debug = false, github = { output = function(ctx) - return '/tmp/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.html' + return '/tmp/' + .. vim.fn.fnamemodify(ctx.file, ':t:r') + .. '.html' end, }, typst = { open = { 'sioyek', '--new-instance' } }, diff --git a/config/nvim/lua/plugins/fzf.lua b/config/nvim/lua/plugins/fzf.lua index ddbd713..53c4b5f 100644 --- a/config/nvim/lua/plugins/fzf.lua +++ b/config/nvim/lua/plugins/fzf.lua @@ -1,5 +1,5 @@ return { - 'barrettruth/fzf-lua', + 'ibhagwan/fzf-lua', after = function() local fzf = require('fzf-lua') local has_nonicons = pcall(require, 'nonicons') @@ -94,6 +94,7 @@ return { fzf_reload.reload() end end, + cmd = 'FzfLua', keys = { { '', diff --git a/config/nvim/plugin/options.lua b/config/nvim/plugin/options.lua index f23f751..d9b0750 100644 --- a/config/nvim/plugin/options.lua +++ b/config/nvim/plugin/options.lua @@ -46,8 +46,9 @@ vim.o.number = true vim.o.relativenumber = true vim.o.signcolumn = 'no' -vim.o.statuscolumn = '%s%C %=%{v:relnum?v:relnum:v:lnum} ' -vim.o.statusline = " %{len(expand('%'))?expand('%:~').' ':''}%h%m%r%=%c:%l/%L %{&ft!=''?&ft:&bt} " +vim.o.statuscolumn = "%{%v:virtnum?'':'%s%C %=%{v:relnum?v:relnum:v:lnum} '%}" +vim.o.statusline = + " %{len(expand('%'))?expand('%:~').' ':''}%h%m%r%=%c:%l/%L %{&ft!=''?&ft:&bt} " vim.opt.path:append('**') diff --git a/home/modules/packages.nix b/home/modules/packages.nix index 592d73e..88f95cf 100644 --- a/home/modules/packages.nix +++ b/home/modules/packages.nix @@ -161,7 +161,7 @@ in font_size 18 status_bar_font_size 18 - inverse_search_command nvim --server /tmp/nvim-preview.sock --remote-expr "execute('b +%2 %1 | normal! zz')" + inverse_search_command nvim-inverse-search %1 %2 ''; }; diff --git a/scripts/nvim-inverse-search b/scripts/nvim-inverse-search new file mode 100755 index 0000000..4a9a13e --- /dev/null +++ b/scripts/nvim-inverse-search @@ -0,0 +1,12 @@ +#!/bin/sh +file="$1" +line="$2" + +for sock in /run/user/$(id -u)/nvim.*.0; do + [ -S "$sock" ] || continue + result=$(nvim --server "$sock" --remote-expr "bufnr('$file')" 2>/dev/null) + if [ "$result" != "-1" ] && [ -n "$result" ]; then + nvim --server "$sock" --remote-expr "execute('b +$line $file | normal! zz')" + exit 0 + fi +done