chrisgrieser / nvim-rip-substitute

Search and replace in the current buffer with incremental preview, a convenient UI, and modern regex syntax.
MIT License
194 stars 8 forks source link

FR: support search/replace for line breaks #28

Open tim-hilde opened 1 day ago

tim-hilde commented 1 day ago

Make sure you have done the following

Bug Description

New lines (\n), carriage returns (\r) or * are not recognized. Possibly more

Relevant Screenshot

image

To Reproduce

Search for/replace with \n, \r or *

Sample Text

this is a test with carraige return and new lines

neovim version

NVIM v0.10.2

ripgrep version

ripgrep 14.1.1

Minimal reproducible config

local spec = {
    {
        "chrisgrieser/nvim-rip-substitute",
        opts = {}, -- insert config here
        keys = {
      { "gs", function() require("rip-substitute").sub() end, mode = { "n", "x" } },
        },
    },
}
--------------------------------------------------------------------------------
vim.env.LAZY_STDPATH = "./nvim-repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro { spec = spec }
chrisgrieser commented 1 day ago

Ah, that's technically not a bug, but simply a feature not supported yet.

Search/replace for line breaks entails quite the need for quite a bit of extra logic (file-format specific line breaks, nvim's editor model working with an array of lines, accounting for match at the border of line ranges, etc.)

Also, the incremental preview of replacements affecting \n require the ability to hide complete lines in the buffer, something to my knowledge neovim core does not support yet. Thus, such a feature cannot even be implemented at the moment.

chrisgrieser commented 1 day ago

(Btw, search/replace for * should be supported, if you escape it via \*. )