Menu

How To Use Macros

2008-01-17
2012-11-13
  • Nobody/Anonymous

    I am new to Notepad++ and I was just wondering what macros are and when is a good time to use them. Thanks.

     
    • Nobody/Anonymous

      A macro is a recording of one, but mostly more action(s), which can be played back to allow you to execute it multiple times. Notepad++ macro recording stores most keystrokes, but isn't able to playback a Find operation using a dialog.

      Here's an example which should duplicate all lines in a file.
      Click the start macro recording button.
      Press Alt+Home to go to the real beginning of the line.
      Press and hold down the SHIFT key.
      Press the CursorDown key.
      Press CTRL+D to duplicate the line.
      Now press CursorDown key again to move the cursor below the duplicate of the line (and clearing the selection).
      Click the stop macro recording button.

      You can now perform this operation again by clicking the macro playback button.
      You can also perform it multiple times by clicking the Run a macro multiple times... button. You can enter a fixed number of times then, or choose to run it until the end of the file.

      Unfortunately, the "end of file" doesn't seem to be updated. If you execute the macro above "until the end of file" it will stop at the line number that was the last when execution started. Because lines have been inserted in the meantime, only a part of the lines will be duplicated.

      Running the macro again, doesn't overcome this problem... You would also have to do this a number of times. Perhaps "end of file" could simple be detected by counting the line number from the bottom instead of from the top, but I guess it would be even easier to just check if the cursor has reached the last line of the document.

       
      • Greg Bullock

        Greg Bullock - 2008-01-26

        >Unfortunately, the "end of file" doesn't seem to be updated. If you execute the macro above "until the end of file" it will stop at the line number that was the last when execution started. Because lines have been inserted in the meantime, only a part of the lines will be duplicated.
        <

        It seems there's a small bug in the stopping condition N++ uses when playing the macro to the end of file.  For most macros, the bug doesn't make any difference, and you can play them to the end of file without problem, but the bug does affect this particular macro.

        I've sent Don a fix for the bug.  If he agrees, then he'll probably put it in a future version of N++ to fix this case.

        Thank you for reporting the error.

        Regards.
        Greg