Skip to content

Commit

Permalink
fix: disallow line breaks in search/replace strings (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Nov 27, 2024
1 parent 2552adb commit 1f09b51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ regex more intuitive. However, if you regularly use named capture groups, you
may want to disable this setting.

## Limitations
- `--multiline` and various other flags are not supported yet.
- Searching/replacing for line breaks (`\n` or `\r`) is not supported. [See
issue #28](https://github.com/chrisgrieser/nvim-rip-substitute/issues/28).
- This plugin only searches the current buffer. To search and replace in
multiple files via `ripgrep`, use a plugin like
[grug-far.nvim](https://github.com/MagicDuck/grug-far.nvim).
Expand Down
5 changes: 5 additions & 0 deletions lua/rip-substitute/rg-operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ function M.incrementalPreviewAndMatchCount()

-- GUARD INVALID SEARCH/REPLACE STRINGS
if toSearch == "" then return end
if toSearch:find("[\n\r]") and toReplace:find("[\n\r]") then
-- see #28 or https://github.com/chrisgrieser/nvim-rip-substitute/issues/28#issuecomment-2503761241
u.notify("Search and replace strings cannot contain newlines.", "error")
return
end

-- DETERMINE MATCHES
local rgArgs = { "--line-number", "--column", "--only-matching", "--", toSearch }
Expand Down

0 comments on commit 1f09b51

Please sign in to comment.