Skip to content

doums/rg.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

rg.nvim

ripgrep integration in nvim

Install

As usual using your plugin manager, e.g. lazy.nvim

local P = {
  'doums/rg.nvim',
  cmd = { 'Rg', 'Rgf', 'Rgp', 'Rgfp' },
}

return P

Config

require('rg').setup({
  -- Optional function to be used to format the items in the
  -- quickfix window (:h 'quickfixtextfunc')
  qf_format = nil,
  -- Glob list of excluded files and directories when the special
  -- `e` flag is set (it uses the `--glob !*` flag of rg)
  excluded = {
    '.idea',
    'node_modules',
    '.git',
    'target',
    'package-lock.json',
    'Cargo.lock',
  },
})

Commands

Each of the following commands spawn rg with the supplied arguments and then populates the quickfix list with the match(es)

NOTE Do not quote the PATTERN argument as when using rg in a terminal. It is automatically quoted by the plugin as expected.

⚠ Positions of command arguments are strict

Rg PATTERN

Make a rg search with defaults, in the current directory

:Rg a pattern

Rgp PATTERN PATH

Make a rg search with defaults, in the provided path

:Rgp a pattern /a/path

Rgf FLAGS PATTERN

Make a rg search with flag(s), in the current directory

Available flags:

  • I--no-ignore
  • H--hidden
  • h--hidden and glob list of excluded files and directories
  • S--smart-case
  • s--case-sensitive
  • i--ignore-case
  • e → glob list of excluded files and directories
:Rgf HIs a pattern

Rgfp FLAGS PATTERN PATH

Make a rg search with flag(s), in the provided path

Same flags as Rgf

:Rgfp HIs a pattern /a/path

API

The plugin module exposes the following methods. Each of them spawn rg with the supplied arguments and then populates the quickfix list with the match(es)

rg

rg(pattern: string, flags: listOf[IHSsiE], path: string)

Example

require('rg').rg('a pattern', { 'H', 'I' }, '/a/path')

rgui

rgui(path: string?)

Uses vim.ui.* interface to query the flag(s) and the pattern. It can take an optional path as argument.

Useful when combined with a file explorer plugin to search under a specific path.

Example with nvim-tree

In the files'tree window press <C-f> to search in the directory/file under the cursor

-- nvim-tree config

local function on_attach(bufnr)
  -- ...

  vim.keymap.set('n', '<C-f>', function()
    local node = api.tree.get_node_under_cursor()
    require('rg').rgui(node.absolute_path)
  end, opts(''))
end

License

Mozilla Public License 2.0