4

I have been using nano to write a bash script and I am at several times indenting various lines at once with Alt + }. The problem is that the following occurs:

enter image description here

Several lines without text in them get white-spaces by the amount that I indent the text and they are coloured green. They don't affect the program but they make it look bad. I have been deleting them one by one but it gets frustrating over time. Is there a way to get rid of all the white-spaces at once? maybe some way to select the text (short cut for selecting text in nano is Alt + a) and have a short cut do it?

Lucas Alanis
  • 1,208
  • 3
  • 15
  • 30

1 Answers1

2

Use global search and replace with the expression ^\s+$.

  1. Switch to search and replace mode with C-\.
  2. Switch to regex mode with Alt-R.
  3. Type the expression ^\s+$.
  4. Hit Enter to replace with an empty string.
  5. On the match, hit A for All.
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • 2
    Note that it seems that there is no way to match a newline using nano's regex. As such, this answer deletes the _contents_ of lines with whitespace, but it does not delete the lines themselves. (This answer matches what the OP wanted, but not the title of the question.) – Phrogz Feb 12 '16 at 16:32