15

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

Community
  • 1
  • 1
Tom Karger
  • 165
  • 1
  • 1
  • 6

3 Answers3

15

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:

  • Whitespace Display Toggle Meta + P - no visible change
  • Verbatim Input Meta + Shift + V then pressing Enter would translate into a visible ^M encoding (but works for a Tab input)
  • "Special Functions" Esc + Esc then a 3 digit sequence - control characters not accepted (but accepts visible chars 013 would actually interpret it like the user pressed Enter)
  • Unicode Input Ctrl + Shift + U - control characters not accepted (but accepts visible chars)

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:

  • Search Ctrl + W
  • Find Next Meta + W*
  • Toggle replace while searching Ctrl + R
  • Search & Replace Ctrl + \

*Meta is usually the Alt key


PS: "sometimes failure is the answer, or someone should prove me wrong"
PPS: please
CSᵠ
  • 9,711
  • 9
  • 37
  • 61
  • 1
    Wow, thanks for the extensive investigation! At least now I can be sure :) – Tom Karger Mar 29 '15 at 13:26
  • Actually, the second bulletin point is incorrect. Instead of "visible ^M", it translates to ASCII 13, or the `CR` character. However Unix linefeeds are `^J` instead. Unfortunately, `meta-V + ctrl-J`doesn't work either. – Antti Haapala Feb 03 '16 at 11:58
6

Not only it is currently not possible to do this in nano, but my feature request was also marked as "wontfix, too hard" in the bug tracker as well.

Antti Haapala
  • 117,318
  • 21
  • 243
  • 279
  • This is no longer true. With external commands and macros, nano has become a text-editing powerhouse. – MarkWeston Jul 03 '18 at 09:29
  • @MarkWeston my answer points to the fact that the editor itself doesn't support it and won't, due to its internal structure, and your answer is the only one that works. – Antti Haapala Dec 18 '18 at 05:01
2
  1. Select the text block.
  2. Press insert command.
  3. Press flipexecute command.
  4. Press flippipe command.
  5. Press flipnewbuffer command.
  6. Execute whatever external command you want. The command will be piped the selection into stdin and the selection will be replaced by stdout of the command.

Furthermore, you can automate this by recording and running macros. You can also bind keys to macro-sequences.

MarkWeston
  • 692
  • 3
  • 15