Sunday, July 26, 2015

Remove empty lines using regular expression in Geany


There were few problems setting the keyboard shortcuts, context actions, search replace while running Geany editor on Windows OS.

One of the instances was to search replace empty lines while running Geany on windows. How to use regular expressions to remove empty lines ?
Well it's just simple, 
Search for: \n\n
Replace with: \n
To make it work on Windows where the line ending is CRLF and not just LF (line feed). The line ending has to set to unix style.

Document -> Set Line Endings -> Convert and Set to LF (Unix)
 Now,
Search for: \n\n
Replace with: \n
Also check the multi-line matching in search replace dialog.


This should work well.

3 comments:

  1. This doesn't always work, use regex & multiline matching - yes, but as pattern use \n^$ meaning "new line" followed by "start of the line" and "end of the line" right after = empty line; and replace it with nothing.

    ReplyDelete
  2. Pattern '....\n^$' did not work for me in Geany 1.36.

    Pattern '....$\n' does work to delete the whole including newline.

    ReplyDelete