Search code examples
bashnano

How to delete several lines containing only whitespaces in nano?


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?


Solution

  • 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.