English 中文(简体)
using Notepad++ how can i make a macro type situation in which a number increments?
原标题:

for example i have about 500 lines. in the beginning of each line i want to add a number. so in line 1 i would want "1)" and then line 2 i would want "2)"

i know i can do a macro in n++, but it wouldn t be incremental. is there any possible way to do this?

最佳回答

Notepad++ Macros only playback keyboard actions. They can t do anything dynamic.

However there is a built-in(?) plugin that can do this for you.

Highlight all the code, then choose "TextFX / TextFX Tools / Insert Line Numbers"

One thing to be aware of is that it is the absolute line number within the file. You can t start numbering on line 10 and make it say line 03 or something like that.

问题回答

Edit -> Column Editor and use the bottom option on that dialogue (Number to Insert). This way you can also start from whatever number you like and not have to have the leading zeros.

In the more general cases where you want to add a sequence number more selectively (e.g. in the middle of a line, or only for some lines), there are two methods:

  1. Hold down alt and use your mouse to drag a rectangular region, as described in http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Column_Editing Then use Edit -> Column Editor -> Number to Insert as per Tom s answer.

  2. Select a rectangular region again as above, copy the single character # to your clipboard, then use TextFX -> TextFX Edit -> Insert (Clipboard) through lines, as described here: http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Clipboard_Uses#Insert_through_lines_variable_text

You could use TextPad if you need a versatile solution to this problem. Just open the replace dialog in it; set replace mode to regex and then in replace by textbox use i where you want an incrementing sequence to be used.

TextFX->TextFX Tools->Insert Line Numbers

I have a suggestion but isn t fully automated.. You can open a new file Press the macro recording button:

  1. insert ayting in the first line and press enter
  2. Stop macro recording
  3. Press "Do it many times" (I don t know how is eng. translation) and specify to repeat it for 499 times.

As answered in question https://superuser.com/questions/331098/flip-or-reverse-line-order-in-notepad do:

  1. Edit > Select All
  2. TextFX > TextFX Tools > Insert Line Numbers
  3. If TextFX > TextFX Tools > +Sort ascending is checked, uncheck it
  4. TextFX > TextFX Tools > Sort lines case sensitive (at column)
  5. TextFX > TextFX Tools > Delete Line Numbers or First Word

I hope it helps, I didn t try it but I can t see how it couldn t work.. :-)





相关问题
C macro processing

I m thinking about best way to write C define processor that would be able to handle macros. Unfortunately nothing intelligent comes to my mind. It should behave exactly like one in C, so it handles ...

Macros as arguments to preprocessor directives

Being faced with the question whether it s possible to choose #includes in the preprocessor I immediately thought not possible. .. Only to later find out that it is indeed possible and you only need ...

Is there a profitable way to record user actions in textarea?

I need to send bunch of commands to the server on timer - like: put(0,"hello") del(4,1) put(4," is around the corner") so I need to monitor and record all of the user input and compile/flush it on ...

taking java method names as function arg in clojure

All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much ...

Removing macro in legacy code

I have a lot of legacy code using macro of the form: #define FXX(x) pField->GetValue(x) The macro forces variable pField be in the scope: ..... FIELD *pField = .... ..... int i = FXX(3); int j = ...

eval during emacs lisp macro expansion

How can I fix the simple macro foo in (elisp)Eval During Expansion? None of the followings work: (defmacro foo1 (a) `(setq (eval ,a) t)) (defmacro foo2 (a) `(setq ,(eval a) t)) (defmacro foo3 (...

热门标签