regexsearchreplacenano

Nano insert newline in search and replace


Basically, I need to doublespace a part of text. I know I can do it with:

sed G

but it would be great if I could do it directly in Nano.

I tried to search for the end of line ($) and then replace it with things like \n or [:newline:] but it seems that RegExp is recognized only for search and not for replace -- it always inserts the literal expression.

However, this question suggests it could be possible. Though I can't figure out how. And yes, I have:

set regexp

in my .nanorc


Solution

  • set regexp in your config file will:

    Do extended regular expression searches by default.

    You can also activate it interactively with Meta + R*

    But that's it! Search using RegEx, but as replacement Nano accepts only strings, except referenced captured groups \1 to \9 .

    Nano's RegEx flavour is a POSIX implementation, and for what would interest you it does not compute [:newline:] but accepts \s, [:cntrl:] (Control characters) and [:space:] (All whitespace characters, including line breaks) also negated POSIX classes: [^[:graph:]]

    Answer

    It can't be done, nothing works, tried:

    ASCII codes for some control characters:

          DEC   HEX   
    (\t)    9  0x09   Horizontal Tab
    (\n)   10  0x0a   New Line
    (\r)   13  0x0d   Carriage Return
     ( )   32  0x20   Space
    

    Nano commands:

    *Meta is usually the Alt key


    PS: "sometimes failure is the answer, or someone should prove me wrong"
    PPS: please