• Stars
    star
    597
  • Rank 74,979 (Top 2 %)
  • Language
    Lua
  • Created about 3 years ago
  • Updated 5 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,675
star
3

telescope-fzf-native.nvim

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

telescope-frecency.nvim

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

telescope-project.nvim

Lua
586
star
6

telescope-media-files.nvim

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

telescope-ui-select.nvim

Lua
404
star
8

telescope-dap.nvim

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

telescope-github.nvim

Integration with github cli
Lua
217
star
10

telescope-symbols.nvim

Lua
193
star
11

telescope-packer.nvim

A Telescope extension that provides extra functionality for Packer.nvim
Lua
180
star
12

telescope-fzy-native.nvim

FZY style sorter that is compiled
Lua
162
star
13

telescope-bibtex.nvim

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

telescope-smart-history.nvim

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

telescope-cheat.nvim

WIP integration
Lua
101
star
16

telescope-arecibo.nvim

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

telescope-hop.nvim

(Teles-)Hopping to the moon.
Lua
90
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