Adding a shortcut to a language....
Charles Buege last edited by
Is there an easy way to add a ‘shortcut’ mapping to change to a particular language? I use Notepad++ to past in SQL or PowerShell code periodically and I’ve love to setup CTRL-ALT-S or CTRL-ALT-P to toggle to those languages directly for a quick visual inspection. Is this doable already or do I need to upvote a feature enhancement somewhere?
PeterJones last edited by
The languages don’t show up in Settings > Shortcut Mapper, so the easiest possibility isn’t there.
The language change doesn’t seem to get recorded in a macro.
I think the issue is that they don’t have a static menu command ID (ie, aren’t listed in menuCmdID.h), so there isn’t a direct way to call them.
However, some of the scripting plugins, like PythonScript (install instructions here), do have a way to search the menus for an existing command, even if they don’t have a static command ID.
notepad.runMenuCommand("Language", "YAML")will change the language to YAML; any languages at the same level will have the same syntax. If you have Preferences > Languages > ☑ Make language menu compact enabled, then the languages under a letter submenu will require a trick: for example Languages > N > Normal Text would be accessed via
notepad.runMenuCommand("N", "Normal Text").
So, if you install PythonScript, then Plugins > Python Script > New Script, and create these two scripts:
from Npp import * notepad.runMenuCommand("S", "SQL")
from Npp import * notepad.runMenuCommand("P", "PowerShell")
Then Plugins > Python Script > Configuration,
- click on
SetLanguageSQL.pyand ADD to the Menu Items list
- click on
SetLanguagePowerShell.pyand ADD to the Menu Items list
Once there, restart Notepad++.
Now Settings > Shortcut Mapper > Plugin Commands will list those two scripts, and you can associate them with keyboard shortcut of your choice.
- click on
BenHastingsFDSU last edited by
@PeterJones Thanks!! This really quite the perfect write-up. Top results off Google and 20 min later, I have icons for “Set Language to SQL” and “Set Language to XML.”
The PytonScript was a little wonky with allowing me to set the icon. It seemed committed to .bmp or .ico files rather than .png. Ok – found those alternatives. But each time I tried to load them, it just didn’t work. But hey – that’s more the plug-in…
Your solution worked like a charm! Thank you!