i have a text document with several lines. Each line ends at different column. I want to add spaces at the end of a each line in notepad++ upto fixed column. How can i do it in notepad++.
-
Here are the answers: https://stackoverflow.com/questions/11003761/notepad-add-to-every-line https://stackoverflow.com/questions/32977132/add-a-character-to-the-end-of-every-lines-in-notepad http://code2care.org/pages/add-text-start-end-each-line-notepad-plus-plus/ – algoquant Feb 10 '19 at 00:15
3 Answers
I have only a very ugly solution with notepad++ without any additional Plugin, but using it once maybe ok. Say you want to expand to a linelength of 80 chars, thus we need to expand each line shorter than 79. We will do several regular expression find/replaces (replace all affected lines in the whole file at once) until all lines have the desired length (i.e. if there is one empty line in the file, to expand it to 80 spaces we have to do 80 Replaces!). Here are the details:
Open the replace Dialog:
- Find what:
(^.{0,79})$
- Replace with:
\1
(there is a space after the 1!) - mark Regular expression in the lower left and select Wrap around
- click Replace All repeatedly until the message in the statusbar of the replace dialog tells yout, that there were no more occurences. (You can hold down Alt-A for a few seconds, so that is not as ugly as it sounds.)

- 9,135
- 3
- 26
- 35
-
It's a good idea to finish the task without additional installations. However, when I tried above replace options it says 'can not find'. I did select 'regular expression' as search mode. – Raju Feb 20 '16 at 14:16
-
Go to the first line of the file before using the dialog or select *wrap around* in the dialog so that the search wraps at the end of the file again to the start, I will update my answer. – Lars Fischer Feb 20 '16 at 14:21
-
-
Each replace adds one space to all short lines. Hold Down ALT-A for several seconds. I will add a screenshot of the dialog that works for me. – Lars Fischer Feb 20 '16 at 14:25
-
Lol, your solution helped me a lot, I think notepad++ developers should add such feature – shjeff Dec 18 '20 at 10:17
Step 1: Append enough characters to each line to make the shortest line to be longer than desired width of the file. For example if desired width of the file is 80 characters, add 80 character to end of each line using regular expression option in replace dialog box in Notepad++. Find: $ Replace with: (80 spaces) Search mode: Regular expression Now we have at least 80 characters with trailing blanks in each line.
Step 2: Replace first 80 characters with those 80 characters followed by a special character like # sign. Find: (^.{80}) Replace with: $1# Search mode: Regular expression
Step 3: Trim trailing blanks. Edit >> Blank Operations >> Trim Trailing Spaces.
Step 4: Replace # sign with empty string.

- 1
- 1