28

How can I repeat the line in notepad++ ?

For example I have the following input:

a 01
a 02
a 03
a 04

And I would like it to become:

a 01
a 01
a 02
a 02
a 03
a 03
a 04
a 04

So every line should be displayed twice.

Paweł Bejger
  • 6,176
  • 21
  • 26
tahafahed
  • 383
  • 1
  • 3
  • 7
  • 1
    While this isn't worthy of an answer, I'd like to point out that notepad++ supports user-created arbitrary plugin creation. http://notepad-plus-plus.org/contribute/plugin-howto.html. Have you considered writing one? – SomeGuy Feb 03 '14 at 22:24
  • Good idea @user834688 - a "zip" plugin would be quite simple to make. – paddy Feb 03 '14 at 22:26

6 Answers6

39

If you don't mind the semi-manual process, you can start at the first line and repeat the following key combination until you reach the end of the document (you get very fast at this)

Ctrl + D Down Down

This duplicates the current line, then moves down twice (to the line following the newly duplicated one).

If you have a large document, you can record this once as a macro (see the Macro menu), then use either Ctrl + Shift + P (Playback) repeatedly -- you can just hold those keys down. Or use the Macro option "Run a Macro Multiple Times..."

paddy
  • 60,864
  • 6
  • 61
  • 103
  • 4
    Technically, you could shorten this procedure by working bottom-up, i.e. duplicate line, move up, duplicate, up, etc. :-) But, as you said, if it's repetitive enough to be annoying, a macro might be worth it. – Amos M. Carpenter Oct 18 '16 at 06:05
39

Open the search dialog box and write :-

Find:

^.*$

Replace:

$0\n$0

Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
Ravi
  • 419
  • 4
  • 5
  • 5
    Make sure to enable regex search in the search dialog and consolidate your linefeeds afterwards (`\n`, `\r` or `\r\n`). – grek40 Feb 20 '16 at 11:48
5

If you have the mouse cursor on the line you want to repeat, then you can use Ctrl-D shortcut to duplicate the line. Or you can use the same shortcut selecting multiple lines.

AdnanJT
  • 284
  • 1
  • 6
  • 2
    Regarding your comment *"Or you can use the same shortcut selecting multiple lines."*... This does not interleave duplicates. Instead, it treats the entire block as one "line" and creates a duplicate copy following the block. – paddy Feb 03 '14 at 22:17
4

Highlight the desired code and press Ctrl+D. Don't highlight if you want to duplicate just the current line.

barbsan
  • 3,418
  • 11
  • 21
  • 28
Maverick
  • 962
  • 9
  • 12
1

To repeat each line with RegEx in NotePad++, press Ctrl + H ; Then:

Find what : ^(.*)$

Replace with : $1\n$1

Note: Select Regular expression in Search Mode and Uncheck ". matches newline"


To repeat each line manually, select the line and press Ctrl + D on your keyboard.

Note: To selecting the whole texts of desired line, click on the line three times (mouse triad-click).

  • 2
    No needs to select the whole line for duplication. Moreover same answer was already given many years ago. – Toto May 08 '22 at 07:51
0

If you are using windows, I recommend writing an auto-hotkey (AHK) script to do this for you. This way, your special text-manipulation script will work in any IDE, not just notepad++. All you would have to do is copy your text example to the clipboard, and then execute an AHK script that reads data from the clipboard using the %clipboard% variable. Then you can load the clipboard with the results of your script and send a CTRL+V signal.

KANJICODER
  • 3,611
  • 30
  • 17