27

I have my default editor for .ahk files set to Notepad++ Portable on my work laptop, but selecting Edit This Script opens files in the standard Windows Notepad.

A post on the AHK forums suggests editing the registry, but I don't see any entries under HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command.

How can I configure AutoHotkey to edit scripts with Notepad++?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225

9 Answers9

37

For whatever reason, the Registry entry doesn't exist by default, but it is recognized by the application once created.

  1. Navigate to HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell in RegEdit.
  2. Right-click the Shell folder, select New > Key and name this Edit.
  3. Right-click the Edit folder, select New > Key and name this Command.
  4. Double click the (Default) string entry in Command.
  5. Paste in "C:\Program Files\Notepad++\Notepad++.exe" "%1" to this window.
  6. Reload AutoHotkey for the changes to take effect.

Note: I don't use Notepad++, but this works for VS Code on my system, and will for N++ as long as the directory information for the executable is correct.


The corresponding .reg file looks like this:

Windows Registry Editor Version 5.00 
[HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command]
@="\"C:\\Program Files\\Notepad++\\notepad++.exe\" \"%1\""
Lilienthal
  • 4,327
  • 13
  • 52
  • 88
David Metcalfe
  • 2,237
  • 1
  • 31
  • 44
  • 1
    How do you "reload AutoHotKey"? Reloading each AHK script in turn doesn't do it. I can relog, but I'm not clear on how to reload AHK in general. – Trey Aug 29 '18 at 15:55
  • @Trey Right click on the application icon in the taskbar, click Exit. Open AutoHotkey again. Otherwise, you could reload it via the related command: https://autohotkey.com/docs/commands/Reload.htm – David Metcalfe Aug 29 '18 at 20:45
  • 1
    Yes, I tried that, but even after doing reload or quit/restart on each one in sequence, Edit didn't change. Since every AHK script runs its own interpreter, perhaps they're pooling a cache containing this, so I'd have to quit every one and then re-open them? I will try relogging when I can, as that's certainly a lot easier since I have a dozen or so scripts. – Trey Aug 29 '18 at 22:07
  • 2
    I didn't have to reload AHK for this to take effect--just clicking save in the registry editor did it for me. – crazybilly Feb 28 '20 at 16:08
  • We should need to give the full path. subl or subl.exe works in cmd but not in the registry. – Smart Manoj Nov 20 '20 at 06:38
  • This has no effect for me using AHK 1.1.33.02 in Win10, even after a reboot. – Bort Jan 17 '21 at 23:12
  • 1
    I feel like there might be some confusion from others around what this is intended to change. To confirm, is this intended to change the Edit This Script button in the system tray, or the Edit context menu item when right-clicking on an .ahk file? – Hashim Aziz Jan 24 '21 at 23:42
  • @HashimAziz Per the original question, the change affects the "Edit This Script" option in AutoHotkey. Changing the context menu when you right-click on a file would require changing registry keys in `HKEY_CLASSES_ROOT\*` or `HKEY_CLASSES_ROOT\Directory` instead of `HKEY_CLASSES_ROOT\AutoHotkeyScript`. – David Metcalfe Jan 25 '21 at 01:09
  • @Bort, are you by chance using the portable version of AHK? I initially used the portable version before installing it, and found that updating the default registry key was not referenced. Instead, I saw from [this AHK forum post](https://www.autohotkey.com/boards/viewtopic.php?p=431572#p431572) to create/update the `HKEY_CURRENT_USER\SOFTWARE\Classes\Applications\AutoHotkey.exe\shell\edit\command` key. – karan.dodia Feb 08 '22 at 21:05
  • This is a great answer. If you need more information or more detailed instructions, or want to see how to configure it for other popular AutoHotkey editors, see https://blog.danskingdom.com/Change-the-default-AutoHotkey-script-editor/ – deadlydog Mar 03 '23 at 17:18
  • Neither registry key helped me until I fixed my .ahk Open association, which was mistakenly set to an editor instead of AHK. – Skull Kid Jul 26 '23 at 03:35
8

The registry entry in item 5 of the previous answer did not work. I don't even know what the extra %* at the end means, so I simplified it to:

"C:\Program Files\Notepad++\Notepad++.exe" "%1"
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • "%*" not found in any answer. %var% -> this represents an variable – Smart Manoj Nov 20 '20 at 01:47
  • "%*" will pass all parameters to Notepad++.exe while "%1" will only pass the first parameter. Hypothetically, if you wanted to open two scripts at once with this, only the first would open. – Skull Kid Jul 25 '23 at 22:32
1

For AHK version 2, changing the registry didn't work for me (I tried both Computer\HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command and Computer\HKEY_CLASSES_ROOT\.ahk\Shell\Edit\Command), but this did it for me. It adds two menu items to the AHK tray menu after a divider:

EditWithNotepadPlusPlus(*)
{
    Run "C:\Program Files\Notepad++\notepad++.exe " A_ScriptFullPath
}
EditWithVsCode(*)
{
    Run "C:\Program Files\Microsoft VS Code\Code.exe " A_ScriptFullPath
}
A_TrayMenu.Add()
A_TrayMenu.Add("Edit with VS Code", EditWithVsCode)
A_TrayMenu.Add("Edit with Notepad++", EditWithNotepadPlusPlus)
return
Jason L.
  • 1,125
  • 11
  • 19
Jerry
  • 221
  • 1
  • 5
  • 11
0

If you are like me and you are hesitant to modify the registry, there is a way to do this using AutoHotKey code.

This is a method I use to edit the script with a different editor. Although I am using Visual Studio Code, the method is the same no matter which editor you want to use. One caveat though: we can't change the existing "Edit This Script" menu item, since that is considered one of the standard menu items and can't be modified. Instead I am adding a new menu item at the top of the menu that says "Edit With Notepad++".

EditWithNotepadPlusPlus()
{
    Run "C:\Program Files (x86)\Notepad++\notepad++.exe" "%A_ScriptFullPath%"
}

; Remove the standard menu items temporarily
Menu, Tray, NoStandard 
; Add our custom menu item labeled "Edit With Notepad++" 
; and calls the function above
Menu, Tray, Add, Edit With Notepad++, EditWithNotepadPlusPlus 
; Add a separator
Menu, Tray, Add 
; Put the standard menu items back, under our custom menu item
Menu, Tray, Standard 

Note: If you're wondering, the lines Menu, Tray, NoStandard and Menu, Tray, Standard are not required. The reason I use those lines is because by default, Menu, MenuName, Add adds menu items to the bottom of the menu. For aesthetic and practical reasons, I prefer Exit to be the last menu item. So Menu, Tray, NoStandard and Menu, Tray, Standard will cause our menu item to appear at the top.

One added benefit of this method is that if you transfer your scripts to a new computer, it should still work (provided you have Notepad++ installed on the other computer). If you edit the registry, you have to remember to edit the registry again.

Cave Johnson
  • 6,499
  • 5
  • 38
  • 57
  • Just tested, this doesn't work :( There is no entry added to the menu. – Mark Jan 08 '20 at 18:05
  • @Mark weird I have been using this code for a while now and it has worked for me so far. I'll check out why it may not be working later. – Cave Johnson Jan 08 '20 at 19:16
  • @Mark Sorry for late reply, but what if you remove all the other lines except for `Menu, Tray, Add, Edit With Notepad++, EditWithNotepadPlusPlus ` and the `EditWithNotepadPlusPlus` function definition at the top. Those are the minimum things needed for this to work. – Cave Johnson Jan 24 '20 at 15:26
  • @KudosJohnson https://imgur.com/bvQhR6l please see that image, it still doesn't do anything. – Mark Jan 25 '20 at 21:04
0

Using AHK v1.1.3.02 on Win10 with string "C:\Program Files\TextPad 8\TextPad.exe" "%1" worked well.

0

The registry change mentioned in other answers for me worked, but you may want to further add the following flags:

C:\Program Files (x86)\Notepad++\notepad++.exe %1  -multiInst -nosession

These flags will stop Notepad++ from recognizing this window as part of your overall session, so it won't overwrite your normal session history or anything.

Edit, a couple years later: I see there's another answer saying they don't want Notepad creating a new session each time so let me elaborate.

If you regularly have Notepad++ open as a text editor with a remembered session, you should use -multiInst -nosession. These flags will cause the editor to create a new instance (-multiInst) every time you open an AHK script for editing, and the opened AHK script will not be remembered as part of your last session when you re-open notepad++ later (-nosession). This is important so that your normal remembered session is unaffected.

If, however, you use Notepad++ EXCLUSIVELY for editing AHK scripts like this, you do NOT want these flags, and you should use only:

C:\Program Files (x86)\Notepad++\notepad++.exe %1

Since I still use Notepad++ as a generic text editor with many, many tabs open, and I don't want my session messed with by anything, I definitely want the flags. But you might not.

R River
  • 43
  • 7
0

Was not working for me, i fixed it by first using the suggestion by R River

C:\Program Files (x86)\Notepad++\notepad++.exe %1  -multiInst -nosession

But this would create a new session each time, so i tried removing the end parameters and it now works.

C:\Program Files (x86)\Notepad++\notepad++.exe %1
0

!!!! hackers !!!!

MUST USE THIS FORMAT:

[HKEY_CLASSES_ROOT\AutoHotkeyScript\shell\edit\command]
@="c:\\TEMP\\Notepad++\\notepad++.exe %L"

Or if editing within REGEDIT then:

c:\TEMP\Notepad++\notepad++.exe %L

******************NOTE: THIS FORMAT WILL NOT WORK:

[HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command]
@="\"C:\\TEMP\\Notepad++\\notepad++.exe\" \"%L\""

******************NOTE: You don't have to restart script or exit/restart AHK application in order to make REGISTRY EDIT take effect. If you change REGISTRY with proper format - changes to default editor will apply immediately, no AHK restart needed.

Vitaliy D
  • 1
  • 1
-4

Simplest way I've found is to:

  1. Right click the .ahk file
  2. Select "Open with" -> "Choose another app"
  3. Check "Always use this app to open .ahk files"
  4. Then select NotePad++ from the list

If it's not listed select "More Apps" and scroll down to NotePad++. (Mind you this example is Windows 10 specific, but previous versions are very similar.)

Editing the registry is great, don't get me wrong, but it takes longer. It's kinda like using a truck to swat a fly! Anyways, hope this works for you. I use it all the time to set the file associations I want.

Lech Migdal
  • 3,828
  • 5
  • 36
  • 63
  • 5
    If you do this then everytime the script will be opened by NotePad++. Thus if you have a start-up script calling the .ahk file, it will not run the script, but instead open it in NotePad++. – Roald Aug 09 '19 at 06:10