25

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.

1
  • Are you working with text that needs to be literally exactly X columns wide? Or do you want a maximum of X columns?
    – Wolfkin
    Commented Jun 13, 2016 at 16:59

4 Answers 4

33
  • 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.
  • There is no Find and replace way to reverse these changes. You will have to use Undo if you want to reverse it.
  • We are changing the text to fix the line length. If you just wish for your text to wrap to the next line at the end of the window, turn on "Word Wrap"
  • ^.{4} means find the first four characters from the beginning of the line in Regex.
  • $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.)
1
  • If the line as list with comma split and you want split only after comma, you can use this regex: ^.{x,y}, y is the max length of line and x is the max length of the any item in the list
    – s-s
    Commented Jul 8 at 14:23
3

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.

2

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.

0

You can use CodVerter Online Text Editor that has a simple tool
exactly for this assignment.
Text can be splitted by a number of characters or by a delimiter.

Navegation: Text Editor>>>Tools>>>Text Splitter enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .