Home

Awesome

rgflow.nvim

Get in the flow with RipGrep. The more you use this plugin, the better you become at using RipGrep from the CLI. Not simply a wrapper which could be replaced by a few lines of config. It's a very simple to use tool aspiring to the Unix philosophy.

3 second intro:

<img src="https://github.com/mangelozzi/rgflow.nvim/assets/19764314/f75cd129-126b-457a-b9c5-ee5c14775069" alt="Core of what the plugin does">

Showing more of the features:

<img src="https://github.com/mangelozzi/rgflow.nvim/assets/19764314/7cace572-086b-46e9-94a5-0a70da0c941c" alt="Showing more details of the plugin">

QuickStart Guide (TL;DR)

  1. Ensure you have RipGrep installed
  2. Set your plugin manager to use mangelozzi/nvim-rgflow.lua and install the plugin.
  3. Create a file for the configuration, e.g. ~/.config/nvim/after/plugin/rgflow.lua
  4. Paste in the minimal configuration code:
require('rgflow').setup(
    {
        -- Set the default rip grep flags and options for when running a search via
        -- RgFlow. Once changed via the UI, the previous search flags are used for 
        -- each subsequent search (until Neovim restarts).
        cmd_flags = "--smart-case --fixed-strings --ignore --max-columns 200",

        -- Mappings to trigger RgFlow functions
        default_trigger_mappings = true,
        -- These mappings are only active when the RgFlow UI (panel) is open
        default_ui_mappings = true,
        -- QuickFix window only mapping
        default_quickfix_mappings = true,
    }
)
  1. After restarting Neovim, press <leader>rg to open the RgFlow UI
  2. Type in a search pattern and press <ENTER>
    • Note: <BS> (Backspace) or - will go up a dir
  3. A search will run and populate the QuickFix window
  4. Press dd to delete a QuickFix entry, or select a visual range and press d
  5. Press TAB to mark a line and <S-TAB> to unmark a line, a line can be marked more than once
  6. Press c/C to :Cfilter/:Cfilter then type a pattern to filter the quickfix results. If you like this plugin please give it a :star:!

Bonus note: Pressing <TAB> when the UI panel is open provides autocomplete for the line you are on (rip grep flags/cwords/filepaths)

Why

<h2 id="features">Features</h2>

Installation

Use your favourite plugin manager, e.g. with Packer:

use("mangelozzi/nvim-rgflow.lua")

And then :PackerSync etc. to install it.

Setup

cmd_flags

Mappings

<details><summary>Default Mappings</summary>
    mappings = {
        trigger = {
            -- Normal mode maps
            n = {
                ["<leader>rG"] = "open_blank",      -- Open UI - search pattern = blank
                ["<leader>rp"] = "open_paste",      -- Open UI - search pattern = First line of unnamed register as the search pattern
                ["<leader>rg"] = "open_cword",      -- Open UI - search pattern = <cword>
                ["<leader>rw"] = "open_cword_path", -- Open UI - search pattern = <cword> and path = current file's directory
                ["<leader>rs"] = "search",          -- Run a search with the current parameters
                ["<leader>ra"] = "open_again",      -- Open UI - search pattern = Previous search pattern
                ["<leader>rx"] = "abort",           -- Close UI / abort searching / abortadding results
                ["<leader>rc"] = "print_cmd",       -- Print a version of last run rip grep that can be pasted into a shell
                ["<leader>r?"] = "print_status",    -- Print info about the current state of rgflow (mostly useful for deving on rgflow)
            },
            -- Visual/select mode maps
            x = {
                ["<leader>rg"] = "open_visual", -- Open UI - search pattern = current visual selection
            },
        },
        -- Mappings that are local only to the RgFlow UI
        ui = {
            -- Normal mode maps
            n = {
                ["<CR>"]  = "start",         -- With the ui open, start a search with the current parameters
                ["<ESC>"] = "close",         -- With the ui open, discard and close the UI window
                ["?"]     = "show_rg_help",  -- Show the rg help in a floating window, which can be closed with q or <ESC> or the usual <C-W><C-C>
                ["<BS>"]  = "parent_path",   -- Change the path to parent directory
                ["-"]     = "parent_path",   -- Change the path to parent directory
                ["<C-^>"] = "edit_alt_file", -- Switch to the alternate file
                ["<C-6>"] = "edit_alt_file", -- Switch to the alternate file
                ["<C-^>"] = "nop",           -- No operation
                ["<C-6>"] = "nop",           -- No operation
            },
            -- Insert mode maps
            i = {
                ["<CR>"]  = "start",         -- With the ui open, start a search with the current parameters (from insert mode)
                ["<TAB>"] = "auto_complete", -- Start autocomplete if PUM not visible, if visible use own hotkeys to select an option
                ["<C-N>"] = "auto_complete", -- Start autocomplete if PUM not visible, if visible use own hotkeys to select an option
                ["<C-P>"] = "auto_complete", -- Start autocomplete if PUM not visible, if visible use own hotkeys to select an option
            },
        },
        -- Mapping that are local only to the QuickFix window
        quickfix = {
            -- Normal
            n = {
                ["d"] = "qf_delete",        -- QuickFix normal mode delete operator
                ["dd"] = "qf_delete_line",  -- QuickFix delete a line from quickfix
                ["<TAB>"] = "qf_mark",      -- QuickFix mark a line in the quickfix
                ["<S-TAB>"] = "qf_unmark",  -- QuickFix unmark a line in the quickfix window
                ["<BS>"]  = "nop", -- No operation
                ["<C-^>"] = "nop", -- No operation - Probably don't want to switch to a buffer in the little quickfix window
                ["<C-6>"] = "nop", -- No operation
            },
            -- Visual/select mode maps
            x = {
                ["d"] = "qf_delete_visual",       -- QuickFix visual mode delete operator
                ["<TAB>"] = "qf_mark_visual",     -- QuickFix visual mode mark operator
                ["<S-TAB>"] = "qf_unmark_visual", -- QuickFix visual mode unmark operator
            }
        },
    }
</details>

Full configuration options

For the full list of configurable settings refer to Default settings

Example Config

This is my personnel configuration:

require("rgflow").setup(
    {
        default_trigger_mappings = true,
        default_ui_mappings = true,
        default_quickfix_mappings = true,
        quickfix = {
            open_qf_cmd_or_func = "botright copen", -- Open the quickfix window across the full bottom edge
        },

        -- WARNING !!! Glob for '-g *{*}' will not use .gitignore file: https://github.com/BurntSushi/ripgrep/issues/2252
        cmd_flags = ("--smart-case -g *.{*,py} -g !*.{min.js,pyc} --fixed-strings --no-fixed-strings --no-ignore -M 500"
            -- Exclude globs
            .. " -g !**/.angular/"
            .. " -g !**/node_modules/"
            .. " -g !**/static/*/jsapp/"
            .. " -g !**/static/*/wcapp/"
        )
    }
)

Lua Commands

CommandDescription
require('rgflow').setup(config)Setup the plugin with the provided config settings
require('rgflow').openOpens the UI with default arguments.<br>Pattern = blank<br>Flags = previous flags (or cmd_flags after startup)<br>Path = PWD
require('rgflow').open(pattern, flags, path, options)Open UI with specified args<br>e.g. require('rgflow').open('foo', '--smart-case --ignore', '~/code/my_project')<br>Refer to section Open Options below for more detail.
require('rgflow').open_blankOpen UI with blank search pattern (insert mode).
require('rgflow').open_cwordOpen UI with current word as the search pattern.
require('rgflow').open_cword_pathOpen UI with current word as the search pattern, and path as the current file's directory.
require('rgflow').open_againOpen UI with previous search pattern.
require('rgflow').open_pasteOpen UI with first line of unnamed register as pattern.
require('rgflow').open_visualOpen UI with current visual selection as pattern.
require('rgflow').startStart searching with current UI parameters.
require('rgflow').closeClose the current UI window.
require('rgflow').search(pattern, flag, path)Execute search immediately with specified args.
require('rgflow').abortAbort current operation (searching or adding results).
require('rgflow').show_rg_helpShow rg --help content in a popup window.
require('rgflow').nopNo operation, useful for disabling hotkeys.
require('rgflow').get_cmdGet last run rip grep command.
require('rgflow').print_cmdPrint last run rip grep command.
require('rgflow').qf_apply_hlAfter removing lines from the QF list by some means outside of RgFlow (e.g. :Cfilter or :Cfilter! command), one can sync the highlighting positions again.
require('rgflow').qf_deleteQuickFix normal mode delete operator.
require('rgflow').qf_delete_lineDelete a line from QuickFix.
require('rgflow').qf_delete_visualQuickFix visual mode delete operator.
require('rgflow').qf_markQuickFix mark a line in the QuickFix window.
require('rgflow').qf_mark_visualQuickFix visual mode mark operator.
require('rgflow').qf_unmarkQuickFix unmark a line in the QuickFix window.
require('rgflow').qf_unmark_visualQuickFix visual mode unmark operator.
require('rgflow').auto_completeAuto complete based on input box context.
require('rgflow').print_statusPrint info about the current state of rgflow.

Open Options

Bonus Tips

Contributing

PR's are welcome!

License

Copyright (c) Michael Angelozzi. Distributed under the same terms as Neovim itself. See :help license.