fzf-lua icon indicating copy to clipboard operation
fzf-lua copied to clipboard

Feature: Global Search Behavior Inspired by VS Code (@, #, $, etc.)

Open Ali-Aref opened this issue 6 months ago • 1 comments

Have you RTFM'd?

  • [x] I have done proper research

Feature Request

Hi everyone — first of all, thank you for this awesome plugin! It’s fast, flexible, and makes Neovim feel like a modern editor.

I’d love to suggest a feature that mimics VS Code’s global search behavior via prefixes in the Ctrl+p menu. The idea is to allow smart, context-aware searches by using specific starting characters. Here's what I mean:

Prefix Behavior
@ Search symbols in current file
# Search workspace/global symbols (via LSP)
no prefix Search files by name
$ Search open buffers

This approach keeps search unified in a single interface while still offering contextual power — similar to VS Code’s Ctrl+p. It would reduce the cognitive load of remembering multiple commands and help users move even faster inside Neovim.

🙋 Is this possible? Is it currently feasible to implement something like this via fzf-lua or fzf.vim? And if so, would it make sense to integrate this behavior into the plugin or expose an interface to let users define prefix handlers?

Thanks again for the great work, and I’d love to hear your thoughts! 🚀


Here is how I have implemented this currently using fzf

return {
  "ibhagwan/fzf-lua",
  dependencies = { "nvim-tree/nvim-web-devicons" },
  opts = {},
  config = function()
    local fzf = require("fzf-lua")
    local config = fzf.config
    local actions = config.actions

    local function vscode_search()
      vim.ui.input({ prompt = "Search: " }, function(input)
        if not input then return end
        
        if input:sub(1, 1) == "#" then
          -- Global/workspace symbols search
          fzf.lsp_workspace_symbols({ query = input:sub(2) })
        elseif input:sub(1, 1) == "@" then
          -- Document symbols search
          fzf.lsp_document_symbols({ query = input:sub(2) })
        else
          -- File search
          fzf.files({ query = input })
        end
      end)
    end

    fzf.setup({})
    
    -- other mappings
    vim.keymap.set("n", "<leader>ff", vscode_search, { desc = "VSCode-like search" })
  end,
}

But this doesn't feel smooth and fast.

Ali-Aref avatar May 20 '25 05:05 Ali-Aref

Is this possible?

Albeit a bit complicated fzf 0.59 made this possible using change-search (within a transform), this is how :FzfLua files line_query=true works where you can input file:line and preview/go to the exact line.

This feature would be more involved as we are switching providers but (without yet looking at the code) I believe it’s possible with some code change in fzf-lua.

We can explore this.

ibhagwan avatar May 20 '25 15:05 ibhagwan

FYI, started working on this so expect a bug or two, if you wanna test it out it's in https://github.com/ibhagwan/fzf-lua/tree/refacator_contents branch, suggestions improvements welcome.

ibhagwan avatar Jul 16 '25 23:07 ibhagwan

Merged #2152, but let’s leave this issue open for now for feedback and improvements.

Resume without “hide” profile is also bugged, I’ll work on it later.

ibhagwan avatar Jul 17 '25 14:07 ibhagwan

Alright, after the last fixes I believe this is working as expected aside from the preview offset in symbols when using previewer=bat|bat_native which I'll have to think of a creative solution.

Fixed the resume, added header, pickers are customizable (can add/remove pickers/prefixes), default looks great:

Image

By default line_query is also enabled which means that you can type fzf:30 and you'll preview/goto line 30 when pressing enter:

Image

Closing the issue, feel free to add feedback anyways.

ibhagwan avatar Jul 17 '25 21:07 ibhagwan

Thanks man, really appreciate it ♥️🎉🎉

Ali-Aref avatar Jul 18 '25 16:07 Ali-Aref

Thanks man, really appreciate it ♥️🎉🎉

You're welcome, last commit should improve on this even more by falling back to btags|tags when the LSP isn't available.

ibhagwan avatar Jul 18 '25 18:07 ibhagwan