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

How to configure this plugin? #9

Closed
ghillb opened this issue Feb 15, 2022 · 5 comments
Closed

How to configure this plugin? #9

ghillb opened this issue Feb 15, 2022 · 5 comments
Assignees

Comments

@ghillb
Copy link

ghillb commented Feb 15, 2022

Currently there doesn't seem to be a way to pass default parameters. For example one has to always type --hidden when searching in dotfiles. Also the rg flag -. (short for --hidden) does not work.

It would be nice, if this plugin could inherit the vim_grep_arguments setting from the default telescope live_grep function.

@alefpereira
Copy link
Contributor

alefpereira commented Feb 16, 2022

@ghillb funny thing, I was just migrating from builtin.live_grep to telescope-rgg.nvim and had the same problem. Couldn't find any docs but taking a look in the code I check there are some ways to do that. You can check the commit if you want, in any case here are some examples:

TLDR: One is to simply pass the new command in the option vimgrep_arguments like that:

:lua require('telescope').extensions.live_grep_raw.live_grep_raw({ vimgrep_arguments = { 'rg', '--hidden'} })

You can also create a function for it, and you can custom whatever you want, for example, you can set default values just like that:

local M = {}
function M.custom_live_grep_raw (opts)
  local defaults = {
    vimgrep_arguments = { 'rg', '--hidden'}
  }
  opts = vim.tbl_extend("force", defaults, opts or {})
  require('telescope').extensions.live_grep_raw.live_grep_raw(opts)
end
return M

And then you could call it by running something like:

:lua require'my.own_module'.custom_live_grep_raw()

As any other picker, you can also customize even more, like adding theme, custom path_display, layout_configs, and so on:

function M.live_grep_raw(opts)
  local defaults = {
    vimgrep_arguments = vim.split(M.vimgrep_arguments, ' '),
    path_display = M.my_custom_path_display,
    theme = 'dropdown',
  }
  opts = vim.tbl_extend("force", defaults, opts or {})
  opts = require("telescope.themes")["get_" .. opts.theme](opts)  -- Apply theme
  require("telescope").extensions.live_grep_raw.live_grep_raw(opts)
end

I also started a fork changing the plugin to make it possible to configure it through the common extension setup recipe. Soon I'll create a PR for this:

telescope.setup{
  extensions = {
    live_grep_raw = {
      vimgrep_arguments = {...}
    }
  }
}
telescope.load_extension('live_grep_raw')

BR

@alefpereira
Copy link
Contributor

Here is the PR #10

@weeman1337 weeman1337 self-assigned this Feb 16, 2022
@ghillb
Copy link
Author

ghillb commented Feb 17, 2022

@alefpereira
Seems like a solid solution, but I tried both, the mapping:

vim.keymap.set({ "n", "v" }, "<c-a-p>", function()
  telescope.extensions.live_grep_raw.live_grep_raw({ vimgrep_arguments = { "rg", "--hidden" } })
end)

and the the config with your branch:

extensions = {
  live_grep_raw = {
    vimgrep_arguments = { "rg", "--hidden" },
  },
}

and both had the following effect:
Screenshot 2022-02-17 195434

@alefpereira
Copy link
Contributor

alefpereira commented Feb 17, 2022

I see, this behavior also happens with builtin.live_grep. This is because rg must have some options for it to output in correct format to be parsed. The "minimum" recommended command is the following:

{
  "rg",
  "--color=never",
  "--no-heading",
  "--with-filename",
  "--line-number",
  "--column",
  "--smart-case"
}

You can check vimgrep_arguments help more details:

:help vimgrep_arguments

I'll include this detail about vimgrep_arguments in the README.md pointing to the help, also going to change the examples to consider this.

@weeman1337
Copy link
Collaborator

live_grep_args now supports the additional_args arg (ha ha) 🙂 See #86 . You can pass args, that are not visible inside the prompt but forwarded to the grep command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants