From 68a728b7b5d94bd9b7af4dd2046671355092200b Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:05:49 +0200 Subject: [PATCH] docs: write them --- README.md | 32 +++++++++++++++++++++++--------- lua/rip-substitute/config.lua | 8 ++++---- lua/rip-substitute/popup-win.lua | 6 +++--- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 10dbf3f..88f0ad6 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,28 @@ A modern substitute for vim's `:substitute` using `ripgrep`. ## Features -- +- Search and replace using `ripgrep` – no more esoteric vim regex to learn. +- Incremental preview of matches and replacements. +- Popup window instead of command line. This means: + + Syntax highlighting of the regex. + + Editing with vim motions. + + No more delimiters decreasing readability. +- Sensible defaults: searches the entire buffer (`%`), all matches in a line + (`/g`), case-sensitive (`/I`). +- Automatic prefill of the search term: cursorword (normal mode), selected text + (visual mode). +- Notification on how many replacements were made (optional). ## Installation +**Requirements** +- `ripgrep` +- nvim >= 0.10 +- `:TSInstall regex` (optional, but recommended) ```lua -- lazy.nvim { - "chrisgrieser/rip-substitute", + "chrisgrieser/nvim-rip-substitute", keys = { { "fs", @@ -44,7 +58,7 @@ A modern substitute for vim's `:substitute` using `ripgrep`. -- packer use { - "chrisgrieser/rip-substitute", + "chrisgrieser/nvim-rip-substitute", } ``` @@ -53,7 +67,7 @@ use { ```lua -- default settings require("rip-substitute").setup { - window = { + popupWin = { width = 40, border = "single", }, @@ -62,11 +76,11 @@ require("rip-substitute").setup { abort = "q", }, regexOptions = { - -- enables lookarounds and backreferences, but slower performance + -- pcre2 enables lookarounds and backreferences, but performs slower. pcre2 = true, -- By default, rg treats `$1a` as the named capture group "1a". When set - -- to `true`, and `$1a` is automatically changed to `${1}a` to ensure the - -- capture group is correctly determined. Disable this setting, if you + -- to `true`, `$1a` is automatically changed to `${1}a` to ensure the + -- capture group is correctly determined. Disable this setting if you -- plan an using named capture groups. autoBraceSimpleCaptureGroups = true, }, @@ -83,8 +97,8 @@ require("rip-substitute").sub() ``` ## Limitations -- `--multiline` is not supported yet. -- Various flags are not supported yet. +- `--multiline` and various other flags are not supported yet. +- The incremental preview does not support *hiding* the search terms. ## About the developer diff --git a/lua/rip-substitute/config.lua b/lua/rip-substitute/config.lua index 34fbf91..c52fec3 100644 --- a/lua/rip-substitute/config.lua +++ b/lua/rip-substitute/config.lua @@ -3,7 +3,7 @@ local M = {} ---@class ripSubstituteConfig local defaultConfig = { - window = { + popupWin = { width = 40, border = "single", }, @@ -12,11 +12,11 @@ local defaultConfig = { abort = "q", }, regexOptions = { - -- enables lookarounds and backreferences, but slower performance + -- pcre2 enables lookarounds and backreferences, but performs slower. pcre2 = true, -- By default, rg treats `$1a` as the named capture group "1a". When set - -- to `true`, and `$1a` is automatically changed to `${1}a` to ensure the - -- capture group is correctly determined. Disable this setting, if you + -- to `true`, `$1a` is automatically changed to `${1}a` to ensure the + -- capture group is correctly determined. Disable this setting if you -- plan an using named capture groups. autoBraceSimpleCaptureGroups = true, }, diff --git a/lua/rip-substitute/popup-win.lua b/lua/rip-substitute/popup-win.lua index dd0fbe2..48a88fc 100644 --- a/lua/rip-substitute/popup-win.lua +++ b/lua/rip-substitute/popup-win.lua @@ -69,11 +69,11 @@ function M.substitute() local rgWin = vim.api.nvim_open_win(state.rgBuf, true, { relative = "win", row = vim.api.nvim_win_get_height(0) - 4, - col = vim.api.nvim_win_get_width(0) - config.window.width - scrollbarOffset - 2, - width = config.window.width, + col = vim.api.nvim_win_get_width(0) - config.popupWin.width - scrollbarOffset - 2, + width = config.popupWin.width, height = 2, style = "minimal", - border = config.window.border, + border = config.popupWin.border, title = "  rip substitute ", title_pos = "center", zindex = 1, -- below nvim-notify