Useful Macros

From Notepad++ Wiki
Jump to: navigation, search
Useful Macros


This page is intended as a repository for user contributed macros. They may have been gleaned on forums or simply added here.

The preferred way of adding a macro is to click on the "+" tab at the top of this page. This automatically opens a new section, to which you will give a title. Then

  • a short description of the macro.
  • a table like in the first example macro.
  • any further comment if appropriate. Commenting every action probably makes it easier to follow the plot. Also, if a user remapped some action, the default key won't do the expected thing, and the comment will help figuring the right key.

It is believed that a common format will help understand the posted macros better.


Toggling line comment on the current line

Notepad++ Edit -> Comment/Uncomment -> Toggle block comment requires something to be selected to be active. This is not convenient. The macro below does the required selecting without losing caret position.

Toggle comment on current line
Key or menu command Reason
Home Goes to first nonindent
Shift+Right Arrow select something. The line should not be empty.
Edit -> Comment/Uncomment -> Toggle block comment toggle comment
End  

New line with exact indentation

When you simply hit Enter to add a new line, the newly created line will be subject to tab-to-spaces conversion, which sometimes isn't what you want.

The following macro creates a new line below current, with exact indentation. Be sure to have nothing selected before using it

New line with exact indent
Key Comment
Ctrl+D Duplicates current line, will remove text next
Down Move there
End  
a Any character. This guarantees cursor is in actual text in processed line
Home  
Ctrl+Shift+Del Removes all text. Cursor is now like youd expect for a new line, indentation was left alone.

New line with exact indentation copied from below

When you simply hit Enter to add a new line, the newly created line will be subject to tab-to-spaces conversion, which sometimes isn't what you want. Also, while it is customary to indent text as the line above, it is sometimes desirable to indent like the line below - like when adding a first line to a block of code.

The following macro creates a new line below current, with exact indentation. Be sure to have nothing selected before using it

New line with exact indent
Key Comment
Down  
Ctrl+D Duplicates line below, will remove text next
Up Back to what will be the inserted line
End  
a Any character. This guarantees cursor is in actual text in processed line
Home  
Ctrl+Shift+Del Removes all text. Cursor is now like youd expect for a new line, indentation was left alone.

Add total virtual space support to Notepad++

The corresponding macro cannot be entered at the keyboard. The following is text to be pasted in shortcuts.xml in order to get it working:

<Macro name="vspace" Ctrl="yes" Alt="yes" Shift="no" Key="100">
  <Action type="0" message="2596" wParam="3" lParam="0" sParam="" />   
</Macro>

You can use NppExec or Python Script plugins to turn this into a script that's run on startup, avoiding to have to hit a menu entry, possibly twice.