Add a string to every line of a selection

11

6

To prepend a string to every line of a selection, I usually use the "increase line indent" (which adds a tab to every line) and then run a search for tab / replace with my string.

Does anyone know how to append a string to every line of a selection?

Muleskinner

Posted 2011-10-27T09:12:39.703

Reputation: 287

3One method of doing the prepend that doesn't involve find/replace is to move your cursor to the start of the first line, hold down Alt + Shift and use the cursor down key to extend the selection to the end of the block. This allows you to type on every line simultaneously – Simon – 2011-10-27T09:26:28.453

I've undeleted my answer below – Simon – 2012-02-28T12:06:00.773

Answers

16

Note: I misread the question initially, so I've posted this as a comment instead as it's still potentially useful but not an answer

One method that doesn't involve find/replace (but only works if you want to do it on every line, including blank lines in your block), is this:

  • Move your cursor to the start of the first line
  • Hold down Alt + Shift and use the cursor down key to extend the selection to the end of the block

This allows you to type on every line simultaneously

Simon

Posted 2011-10-27T09:12:39.703

Reputation: 4 232

At least in my current Notepad++ version (7.7.1) this only works if the lines have the same length, otherwise it will insert on every line at the same column as the length of the first line of the selection. – jonathan – 2019-09-05T13:41:42.217

Thanks, did not find an answer to my specific question but this solved my problem / very useful. – Muleskinner – 2012-02-28T12:29:32.540

@Simon Simply superb – prabhakaran – 2012-05-27T10:33:38.487

5

  1. Choose Search -> Find
  2. Select the Replace tab
  3. Choose Regular expression as Search Mode in the bottom left
  4. Enter as Find what: $
  5. Enter as Replace with: the string you want to have at the end of the lines
  6. Check In selection
  7. Click Find Next or Replace All

This site is nice for testing regular expressions and has a quick reference:

http://rubular.com/

kek

Posted 2011-10-27T09:12:39.703

Reputation: 283

But ^ is start of line, guess you mean $? But anyway, both gives me "The regular expression to search is formed badly" – Muleskinner – 2011-10-27T09:53:07.423

Still gives me "The regular expression to search is formed badly", im using Notepad++ v.5.6.4 (unicode) – Muleskinner – 2011-10-27T10:25:20.657

Yes, I read your question wrong first, but then I updated my answer. Don't know what it is, then. I have Notepad++ 5.9.3 on Windows 7. Maybe you can try upgrading, in case this error is specific to your version of Notepad++?

Also maybe you can try to search for regular expression "a" or "." to see if it is regular expressions in general that don't work in your setup. – kek – 2011-10-27T10:43:23.880

4

Replace the regular expression $ with the string you want.

phihag

Posted 2011-10-27T09:12:39.703

Reputation: 2 557

it gives me "The regular expression to search is formed badly", how should I format the $? – Muleskinner – 2011-10-27T09:39:08.280

3

Alternatively,

  1. Choose Search -> Replace
  2. Choose Extended for Search Mode
  3. Find what: \n
  4. Replace with: Whatever\n

Note that if you leave off the \n in the Replace with, all your lines will be pasted together (which is probably not what you want).

I usually leave Notepad++ in Extended mode because it allows me to optionally paste lines to gether (by removing \n) or split them (by inserting \n), and doesn't get confused by special characters like *+() etc. (Which I am often searching for in C++ code.)

user103102

Posted 2011-10-27T09:12:39.703

Reputation: 31

0

ABOUT selected lines,i have a trick 1.first,learn to how insert every line at start and line.(https://www.youtube.com/watch?v=SiPLZzRqEwM) 2.cut the text(you want to do),paste these a new file (in notepad) 3.insert(according to 1) 4.cut these and paste to your origin file

一个患有癌并且卓越的工程师来陆家嘴搞金融显然是为了理想哈哈哈

Posted 2011-10-27T09:12:39.703

Reputation: 101

Please read the question again carefully. Your answer does not answer the original question. – DavidPostill – 2016-07-14T09:33:29.267

if you try do these ,it will work. – 一个患有癌并且卓越的工程师来陆家嘴搞金融显然是为了理想哈哈哈 – 2016-07-23T09:32:08.630

-1

This can be done using notepad++. Its explained here step by step. http://dotnet-programming-solutions.blogspot.ae/2012/11/how-to-add-text-to-beginning-or-end-of.html Basically its a regular expression match and replace. It is so simple as find->replace all.

user205987

Posted 2011-10-27T09:12:39.703

Reputation: 171

1This adds nothing that has not already been said. – teylyn – 2013-03-11T07:13:06.473