Notepad++ split line after given number of characters

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

Yes, this is possible.

If you do a search/replace and use Regex as option, the following regex will allow you to split a line in two.

^(.{4})(.+)

Replace the number 4 with the amount of chars you want to find. Replace with $1 and $2 to find the first and second string. Replacing it with $1-$2 will place a - in between both strings.


You see to be asking about how to wrap text. Depending on your use you may want a soft wrap or a hard wrap.

soft wrap
This means that the text will split at X columns wide but when you copy and paste it to say MS Word it will expand again to fill the page. In otherwords it's just a visual compression

hard wrap
This means N++ will actually add newlines (Carriage Returns, enter whatever you want to call them*). I presume this is what you want.

There's a number of ways to do it.

  1. Use EOL functions (Split Line)
  2. Regular Expressions
  3. TextFx Plugin

Off about 80 seconds of testing I'd recommend the TextFx Plugin. It depends how firm you want that split to be.

* - though yes I understand that CF/LF are different.