Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request - hide result line in result view if preview is shown #2507

Open
Jendker opened this issue May 10, 2023 · 6 comments
Open

Request - hide result line in result view if preview is shown #2507

Jendker opened this issue May 10, 2023 · 6 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@Jendker
Copy link

Jendker commented May 10, 2023

When I'm using livegrep with telescope often the results are difficult to follow because the result line is shown next to file path text. Example below:
Screenshot from 2023-05-10 13-27-22

Text is difficult to read because it feels like results on different line overlap with the file name.

Another benefit of not having the result line shown would be that the file path would fit more often without truncating.

It would be great if it would be possible to disable the result line in the results view if preview is shown (terminal is wide enough for preview to be shown) and show only the file paths with line no.

@Jendker Jendker added the enhancement Enhancement to performance, inner workings or existent features label May 10, 2023
@micmalti
Copy link

micmalti commented Aug 2, 2023

Based on this, you can comment out this line from Telescope's make_entry.lua and replace it with the line:
display_filename,

However, a more persistent solution is to write your own entry maker with this tweak and pass it as an option to live_grep.

@GeorgiChochev
Copy link

You can achieve this by extending the config

require("telescope").setup({
      defaults = {
        vimgrep_arguments = {
          "rg",
          "--color=never",
          "--no-heading",
          "--with-filename",
          "--line-number",
          "--column",
          "--smart-case",
        },
        -- ... rest of your telescope setup
      },
      pickers = {
        live_grep = {
          vimgrep_arguments = {
            "rg",
            "--color=never",
            "--no-heading",
            "--with-filename",
            "--line-number",
            "--column",
            "--smart-case",
            "-l",
          },
        },
      },
    })

the "-l", arg passed to ripgrep will print only the filenames
Screenshot from 2023-10-18 16-57-10

@mikelerch
Copy link

@GeorgiChochev

Thanks a lot, this works great.
Can you think of a way to hide the : at the end?

@teocns
Copy link

teocns commented Jan 9, 2024

Can you think of a way to hide the : at the end?

@mikelerch You need to create your own telescope.pickers.entry_display

I'll share with you my custom finder for harpoon:

Code
return finders.new_table({
  results = filter_empty_string(harpoon:list(opts.name).items),
  entry_maker = function(entry)
    local filepath = entry.value
    -- print(vim.inspect(entry))

    local entry_items = {
      {
        width = 2,
      },
      {
        width = #entry.context.name,
      },
      { remaining = true },
    }

    local displayer_entries = {
      {
        entry.context.icon,
        "DevIconC",
      },
      {
        entry.context.name,
        "LspInfoList",
      },
      {
        Path:new(filepath):make_relative(vim.loop.cwd())
        .. ":"
        .. entry.context.pos[1]
        .. ":"
        .. entry.context.pos[2],
        "TeleScopeResultsIdentifier",
      },
    }

    local displayer = entry_display.create({
      separator = " ",
      items = entry_items,
    })

    local make_display = function(_)
      return displayer(displayer_entries)
    end
    return {
      value = entry,
      ordinal = filepath,
      display = make_display,
      lnum = entry.context.pos[1],
      col = entry.context.pos[2],
      filename = entry.value,
    }
  end,
})

@tommdq
Copy link

tommdq commented Jun 6, 2024

You can achieve this by extending the config

require("telescope").setup({
      defaults = {
        vimgrep_arguments = {
          "rg",
          "--color=never",
          "--no-heading",
          "--with-filename",
          "--line-number",
          "--column",
          "--smart-case",
        },
        -- ... rest of your telescope setup
      },
      pickers = {
        live_grep = {
          vimgrep_arguments = {
            "rg",
            "--color=never",
            "--no-heading",
            "--with-filename",
            "--line-number",
            "--column",
            "--smart-case",
            "-l",
          },
        },
      },
    })

the "-l", arg passed to ripgrep will print only the filenames Screenshot from 2023-10-18 16-57-10

This works! but it removes the highlight of the grepped text. Any workaround for that?

@Ajaymamtora
Copy link

You can achieve this by extending the config

require("telescope").setup({
      defaults = {
        vimgrep_arguments = {
          "rg",
          "--color=never",
          "--no-heading",
          "--with-filename",
          "--line-number",
          "--column",
          "--smart-case",
        },
        -- ... rest of your telescope setup
      },
      pickers = {
        live_grep = {
          vimgrep_arguments = {
            "rg",
            "--color=never",
            "--no-heading",
            "--with-filename",
            "--line-number",
            "--column",
            "--smart-case",
            "-l",
          },
        },
      },
    })

the "-l", arg passed to ripgrep will print only the filenames Screenshot from 2023-10-18 16-57-10

This works! but it removes the highlight of the grepped text. Any workaround for that?

Hi did you end up finding a fix for this? I keep running into this issue and don't know how to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

7 participants