Notepad++ split line after given number of characters

linebreaksnotepadtext-editors

Is there a way in notepad++, to split one line text, to text with given maximum number of characters in one line? I found only undefined line split in lines operations.

Best Answer

  • Press CTRL+H to bring up Search and replace.
  • In the find what box enter: ^.{4}
  • Where 4 may be modified to any number representing the number of characters you want per line.
  • In the replace field enter $0\r\n
  • In search mode select "Regular expression"
  • To wrap all lines click "Replace All"

Notes:

  • Before using "Replace all" you may want to click "Find next" and "Replace" a few times to verify that your search is working the way you intend it to.
  • Note that there is no Find and replace way to reverse these changes. You will have to use Undo if you want to reverse it.
  • Note that we are changing the text to fix the line length. If you just want to see long lines in the window in the view menu select "Word Wrap".
  • ^.{4} means starting from the beginning of the line find the first 4 characters.
  • $0\r\n means take the information found and replace it with that same information followed by a carriage return and a line feed. (Note that in *nix systems carriage returns and line feeds are dealt with differently.)
Related Question