143

I have recorded a macro that I want to share with my work colleague.

In what location are these recorded macros saved, so that I can add it to his machine?

If interested, the macro is for taking a list of values and adding quotes and comma so that it can be used in the WHERE clause of of an SQL query (WHERE x IN ('value1','value2','value3')).

uınbɐɥs
  • 7,236
  • 5
  • 26
  • 42
heedfull
  • 3,071
  • 3
  • 17
  • 11
  • 1
    Wow... I came up with a macro that does exactly that and wanted to export it for almost the same reason and found your post. Goes to show how much of what programmers do is re-inventing the wheel :/ would be nice if notepad++ has a community for sharing macros. – user193130 Feb 25 '17 at 03:59
  • For those looking to actually program macros (in python): http://npppythonscript.sourceforge.net/ (available as a plugin from within notepad++'s plugin manager) – User Mar 19 '18 at 12:14

8 Answers8

168

In Windows the macros are saved at %AppData%\Notepad++\shortcuts.xml (Windows logo key + E and copy&paste %AppData%\Notepad++\)

Or:

  • In Windows < 7 (including Win2008/R2) the macros are saved at C:\Documents and Settings\%username%\Application Data\Notepad++\shortcuts.xml
  • In Windows 7|8|10 C:\Users\%username%\AppData\Roaming\Notepad++\shortcuts.xml

Note: You will need to close Notepad++ if you have any new macros you want to 'export'.


Here is an example:

<NotepadPlus>
    <InternalCommands />
    <Macros>
        <Macro name="Trim Trailing and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
            <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
            <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
        </Macro>
        <Macro name="abc" Ctrl="no" Alt="no" Shift="no" Key="0">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="a" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="b" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="c" />
        </Macro>
    </Macros>
    <UserDefinedCommands>....

I added the 'abc' macro as a proof-of-concept.

Cos Callis
  • 5,051
  • 3
  • 30
  • 57
Harrison
  • 8,970
  • 1
  • 32
  • 28
  • 14
    I had to close and open notepad++ again to see the changes in the files for a macro I just recorded. – Michel Apr 13 '11 at 12:12
  • 3
    By the way, you can use %username% instead of [username] and it works automatically when pasted to explorer's address bar. – kor_ Nov 07 '12 at 13:24
  • 6
    I found that I had to edit the shortcuts.xml in a different editor otherwise Notepad++ just overwrote my changes when I closed it... Also you can use `%appdata%` in Explorers address bar to get straight into the Roaming or Application Data directories. – Zhaph - Ben Duguid Mar 20 '14 at 10:46
  • 1
    yes, edit it in another text editor, otherwise Notepad++ keeps overwriting it. – Jose Ospina Jun 23 '15 at 15:49
  • It's possible to merge several macro in one (the operation will be done one after the other). It's very intuitive: just remove the end macro tags after the first one + the tags introducing the second one, (only the first macro will appear on notepad++). Launch it, and it will launch the operation of the first + the operation of the second macro that has been added to the end of the first). (@Zhaph, I did edit my macro using notepad++, no problem) – JinSnow Mar 17 '16 at 08:59
  • If you use the AppData environment variable, you can specify a single path which will be valid on all versions of Windows, both old and new; %AppData%\Notepad++\shortcuts.xml – Valiante Apr 23 '18 at 10:49
  • Note: Newly added macros won't reflect until you close Notepad++ – Ujjwal Singh Oct 11 '20 at 21:26
39

For Windows 7 macros are stored at C:\Users\Username\AppData\Roaming\Notepad++\shortcuts.xml.

uınbɐɥs
  • 7,236
  • 5
  • 26
  • 42
DJB
  • 391
  • 3
  • 3
  • 1
    Just deleted some old macros and made a new macro. For me the macros where saved or deleted to shortcuts.xml first **after** saving any/random file in Notepad++, took a while to figure it out. – Liu Kang Jul 11 '13 at 06:53
  • Or just use this, which will work in all cases: `%APPDATA%\Notepad++\shortcuts.xml` – pbarney Dec 26 '22 at 19:30
5

Hit F6

Insert::

npp_open $(PLUGINS_CONFIG_DIR)\..\..\shortcuts.xml

Click OK

You now have the file opened in your editor.


Before altering things checkout the related docs:

Wolf
  • 9,679
  • 7
  • 62
  • 108
Thell
  • 5,883
  • 31
  • 55
  • 2
    The contents of a macro definition can be edited only in the shortcuts.xml file: there is no built-in interface in Notepad++. For more information on the details of how the macros are stored, and the syntax involved, see the [Configuration Files Details: section.](https://npp-user-manual.org/docs/config-files/#macros) – Mesut Akcan Jan 01 '20 at 10:01
  • 2
    What does [F6] mean to you? In my configuration it does nothing. – Wolf Mar 05 '20 at 13:50
  • @Wolf It looks like they may be using the NppExec plugi - https://github.com/d0vgan/nppexec – Richard Feb 05 '22 at 20:24
4

On Vista with virtualization on, the file is here. Note that the AppData folder is hidden. Either show hidden folders, or go straight to it by typing %AppData% in the address bar of Windows Explorer.

C:\Users\[user]\AppData\Roaming\Notepad++\shortcuts.xml
Dave Walker
  • 153
  • 1
  • 8
3

You can find the shortcuts.xml in AppData\Roaming\Notepad++\ path only when using the default settings. If you have backup configured, you can find and set the path in Preferences -> Backup -> Backup path.

When these settings are applied, files in AppData directory won't be used.

Ko Cour
  • 929
  • 2
  • 18
  • 29
1

If you install Notepad++ on Linux system by wine (In my case desktop Ubuntu 14.04-LTS_X64) the file "shortcuts.xml" is under :

$/home/[USER-NAME]/.wine/drive_c/users/[USER-NAME]/My Documents/.wine/drive_c/Program Files (x86)/Notepad++/shortcuts.xml

Thanks to Harrison and all that have suggestions for that isssue.

1

Notepad++ will forget your macros unless you map them to hotkeys via Settings - Shortcut mapper - Macros before exiting Notepad++ (as per https://superuser.com/questions/332481/how-can-i-add-a-macro-in-notepad. Tested with Notepad v6.8.3 on Windows7.)

Community
  • 1
  • 1
gherson
  • 169
  • 2
  • 9
0

Go to %appdata%\Notepad++ folder.

The macro definitions are held in shortcuts.xml inside the <Macros> tag. You can copy the whole file, or copy the tag and paste it into shortcuts.xml at the other location.
In the latter case, be sure to use another editor, since N++ overwrites shortcuts.xml on exit.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Harish Pathak
  • 1,567
  • 1
  • 18
  • 32