11

I have a fairly simple request, but I can't figure out how to do this in Notepad++. I need to create a list where each line begins with a number, starting from 1 and ending at 156. Obviously I dont' want to sit and type this in manually, as I will be creating more than one list.

1
2
3
.
.
.
.
156

How do I do that? I tried the macro function but it only plays back keyboard actions. It does not increment the sequence by 1 as Excel would do with its auto-fill feature. I know Excel can do it, but I must avoid using Excel.

a

As you can see I don't have any columns, or any lines of code. I am starting off from an empty document. I just want to create a long list in a text file.

  • I had a look at "TextFX / TextFX Tools / Insert Line Numbers" and "Edit -> Column Editor" as discussed here. But that's not working for this type of situation. My situation is too simple. :) – Samir Feb 17 '14 at 10:50
20

In Notepad++ you can press Alt+C for the column / multi-selection editor and use the number to insert function from initial number increasing by 1, you'll just need to select all of your lines that you want to number.

You'll need to have blank lines already. I had to select the lines from the bottom up to the top before running the column editor, but I'm not sure if that's required.

essentially sourced from StackOverflow

| improve this answer | |
  • I'm not sure you understood the situation. That's just it. It's a "column editor". I don't have any columns, or any lines of code. I am starting off from an empty document. I just want to create a long list in a text file. And if at all possible, I want to cheat using Notepad++ because I don't feel like typing in each number on each new line on and on. – Samir Feb 17 '14 at 11:32
  • You need to have all your lines, highlight from the bottom to the top and then use the column editor. – Raystafarian Feb 17 '14 at 12:07
  • If you can expand your answer to include the bit about inserting new lines we discussed above, I will mark it as a solution. – Samir Feb 17 '14 at 12:43
  • I added in what I mentioned – Raystafarian Feb 17 '14 at 14:01
  • As promised, I have marked your answer as the solution. Cheers! – Samir Feb 17 '14 at 14:12
5

Answer provided by Raystafarian is essentially correct.

Please open a new document. Record a macro with only 'Carriage return'. Now play the macro 155 times. So you have 156 lines. Now follow the procedure suggested by Raystafarian.

| improve this answer | |
  • Got it! That's essentially what I did. I just didn't use a macro to create new lines. And I didn't realize at first that I had to have the lines created first, to use the Column Editor. – Samir Feb 17 '14 at 12:12
  • Thanks for the macro tip! It simplifies things a bit more. Just a small note, after recording the macro, you have to go back to the beginning of the first line. Then you play the macro 155 times. – Samir Feb 17 '14 at 12:14
  • No, you don't have to go to the beginning of the first line. While recording the macro you have already created the first line. Now play the macro 155 times ( Option Run a macro multiple times ) to get the 156 ( 1 + 155 ) lines. Now ctrl + Home will get you to the beginning. – Wishwas Feb 17 '14 at 12:22
  • I don't think so. While on line 1, you start recording, press Enter, and you are on line 2. You stop recording. You go to "Run a macro multiple times" and play it 155 times. Your last line is 157. Because 2+155=157. So you have to either go back 1 line, or play the macro 154 times instead. – Samir Feb 17 '14 at 12:30
  • OK, so I made the usual off-by-one error. – Wishwas Feb 17 '14 at 13:46
1

This isn't the solution you asked for, but solves your problem easily: Just open excel or google sheets and enter 1 and 2 in the first two cells. Then click and drag the bottom-right corner down to auto-increment the list.

enter image description here

Then just cut and paste it into your text file.

enter image description here

| improve this answer | |
0

Bingo! I have found a way to do it using the Column Editor.

  1. Ctrl+N to create a new empty document.
  2. Go to Settings menu, Preferences, Editing, and make sure "display line number" option is enabled. Click Close.
  3. Press and hold Enter until you have reached line number 156.
  4. Ctrl+Shift+Home to select all the lines (i.e. "columns") from the bottom most to the one on the top. It is necessary to start from the bottom and go up with the selection, so that the text input cursor sits at the beginning of first line whilst everything else is selected down below.
  5. Alt+C to open the "Column / Multi-Selection Editor".
  6. Select "Number to Insert", type in 1 in "Initial number" and 1 in "Increase by". Select "Dec" for decimal numbers, and click OK.
| improve this answer | |
  • I've removed the rather pointless comments here. The thing is – if someone answers your question, it's common for the OP to amend the answer to include some additional steps if necessary. Posting another answer is fine, but often quite redundant since other posts can (and should) be edited to be improved. – slhck Feb 17 '14 at 18:41
  • Upvoted because this is the most complete answer here, and the other answers were confusing (incomplete). However, @slhck is right, as per SuperUser guidelines, it is best practice to update your original question, such as "UPDATE: (12/27/16)", then brief description of the update, followed by a line or some separator, then "ORIGINAL POST:", followed by the original post. This method will make help to organize your newly edited question so that it is more understandable. – Eric Hepperle - CodeSlayer2010 Dec 27 '16 at 17:49
0

Old question but here is an alternative answer (not using notepad++) for anyone looking for the same result.

In command prompt:

FOR /L %A IN (1,1,156) DO ECHO %A >> outputfile.txt

This will start at 1, increment by 1, end at 156. It will append each number as output to outputfile.txt

sample of outputfile.txt:

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
| improve this answer | |
-1

Just do it like a real super user...

perl -e "open(my $fh, '>output.log'); print $fh ($_) for(1..156); close $fh;"

| improve this answer | |
  • 2
    Can you turn this into a teachable moment for those who aren't yet super users? Add a couple of sentences that explain how this works. Thanks. – fixer1234 Dec 8 '15 at 21:09
  • 3
    While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill Dec 9 '15 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.