Configure Autohotkey to edit scripts with Notepad++

Viewed 9691

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++?

8 Answers

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.

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

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

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. I don't remember where I first found these solutions but I'm switching computers atm and found them in my registry and noticed they weren't mentioned anywhere in this thread.

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

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.

Related