• Stars
    star
    521
  • Rank 81,931 (Top 2 %)
  • Language
    Lua
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Live grep with args

Telescope live grep args

REUSE status

Live grep args picker for telescope.nvim.

What it does

It enables passing arguments to the grep command, rg examples:

  • foo → press <C-k> → "foo" → "foo" -tmd
    • Only works if you set up the <C-k> mapping
  • --no-ignore foo
  • "foo bar" bazdir
  • "foo" --iglob **/bar/**

Find the full ripgrep guide here to find out what is possible.

Installation

Packer Add `telescope-live-grep-args.nvim` as `telescope.nvim` dependency, e.g.:
use {
  "nvim-telescope/telescope.nvim",
  requires = {
    { "nvim-telescope/telescope-live-grep-args.nvim" },
  },
  config = function()
    require("telescope").load_extension("live_grep_args")
  end
}
Other Once live grep args is available as lua module, load the extension:
require("telescope").load_extension("live_grep_args")

Setup

Map live grep args:

keymap.set("n", "<leader>fg", ":lua require('telescope').extensions.live_grep_args.live_grep_args()<CR>")

Call live grep args:

:lua require("telescope").extensions.live_grep_args.live_grep_args()

Usage

Options

Name Description
search_dirs Directory/directories/files to search. Paths are expanded and appended to the grep command.

Grep argument examples

(Some examples are ripgrep specific)

Prompt Args Description
foo bar foo bar search for „foo bar“
"foo bar" baz foo bar, baz search for „foo bar“ in dir „baz“
--no-ignore "foo bar --no-ignore, foo bar search for „foo bar“ ignoring ignores
"foo" --iglob **/test/** search for „foo“ in any „test“ path
"foo" ../other-project foo, ../other-project search for „foo“ in ../other-project

If the prompt value does not begin with ', " or - the entire prompt is treated as a single argument. This behaviour can be turned off by setting the auto_quoting option to false.

Configuration

local telescope = require("telescope")
local lga_actions = require("telescope-live-grep-args.actions")

telescope.setup {
  extensions = {
    live_grep_args = {
      auto_quoting = true, -- enable/disable auto-quoting
      -- define mappings, e.g.
      mappings = { -- extend mappings
        i = {
          ["<C-k>"] = lga_actions.quote_prompt(),
          ["<C-i>"] = lga_actions.quote_prompt({ postfix = " --iglob " }),
        },
      },
      -- ... also accepts theme settings, for example:
      -- theme = "dropdown", -- use dropdown theme
      -- theme = { }, -- use own theme spec
      -- layout_config = { mirror=true }, -- mirror preview pane
    }
  }
}

This extension accepts the same options as builtin.live_grep, check out :help live_grep and :help vimgrep_arguments for more information. Additionally it also accepts theme and layout_config.

Mapping recipes:

This table provides some mapping ideas:

Mapped function Description Example
actions.quote_prompt() Quote prompt foo → "foo"
actions.quote_prompt({ postfix = ' --iglob ' }) Quote prompt and add --iglob foo → "foo" --iglob
actions.quote_prompt({ postfix = ' -t' }) Quote prompt and add -t foo → "foo" -t

Shortcut functions

Live grep args ships some additional shortcuts you can map.

This is an example to live grep for the word under the cursor:

local live_grep_args_shortcuts = require("telescope-live-grep-args.shortcuts")
keymap.set("n", "<leader>gc", live_grep_args_shortcuts.grep_word_under_cursor)

Available shortcuts:

Name Action Options
grep_word_under_cursor Start live grep with word under cursor
  • postfix: postfix value to add; defaults to -F (Treat the pattern as a literal string)
  • quote: Whether to quote the value; defaults to true
  • trim: Whether to trim the value; defaults to true
grep_visual_selection Start live grep with visual selection see grep_word_under_cursor

Development

Running the tests

Acknowledgements

Based on the idea of this pull request.

More Repositories

1

telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
Lua
11,260
star
2

telescope-file-browser.nvim

File Browser extension for telescope.nvim
Lua
1,497
star
3

telescope-fzf-native.nvim

FZF sorter for telescope written in c
C
1,236
star
4

telescope-frecency.nvim

A telescope.nvim extension that offers intelligent prioritization when selecting files from your editing history.
Lua
654
star
5

telescope-project.nvim

Lua
548
star
6

telescope-media-files.nvim

Telescope extension to preview media files using Ueberzug.
Lua
415
star
7

telescope-ui-select.nvim

Lua
404
star
8

telescope-dap.nvim

Integration for nvim-dap with telescope.nvim
Lua
280
star
9

telescope-github.nvim

Integration with github cli
Lua
209
star
10

telescope-packer.nvim

A Telescope extension that provides extra functionality for Packer.nvim
Lua
179
star
11

telescope-symbols.nvim

Lua
170
star
12

telescope-fzy-native.nvim

FZY style sorter that is compiled
Lua
162
star
13

telescope-smart-history.nvim

A history implementation that memorizes prompt input for a specific context
Lua
108
star
14

telescope-bibtex.nvim

A telescope.nvim extension to search and paste bibtex entries into your TeX files.
Lua
101
star
15

telescope-cheat.nvim

WIP integration
Lua
101
star
16

telescope-arecibo.nvim

A Neovim Telescope extension for searching the web!
Lua
87
star
17

telescope-hop.nvim

(Teles-)Hopping to the moon.
Lua
87
star
18

telescope-fzf-writer.nvim

Incorporating some fzf concepts with plenary jobs and telescope
Lua
71
star
19

telescope-rs.nvim

Experimental features for telescope in RUST? The safest telescope known to HUMANITY
45
star
20

telescope-vimspector.nvim

Integration for vimspector with telescope.nvim
Lua
38
star
21

telescope-z.nvim

Z integration for Telescope
Lua
35
star
22

telescope-node-modules.nvim

An extension that provides its users with node packages under node_modules directory
Lua
31
star
23

telescope-ghq.nvim

Lua
24
star
24

telescope-snippets.nvim

snippets.nvim integration
Lua
13
star