• Login
Community
  • Login

Adding a shortcut to a language....

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 4 Posters 2.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C
    Charles Buege
    last edited by Dec 6, 2019, 4:53 PM

    Hey all!

    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?

    Thanks!
    Charles

    1 Reply Last reply Reply Quote 1
    • P
      PeterJones
      last edited by Dec 6, 2019, 5:17 PM

      Interesting question.

      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.

      PythonScript’s 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:
      SetLanguageSQL.py

      from Npp import *
      notepad.runMenuCommand("S", "SQL")
      

      SetLanguagePowerShell.py

      from Npp import *
      notepad.runMenuCommand("P", "PowerShell")
      

      Then Plugins > Python Script > Configuration,

      • click on SetLanguageSQL.py and ADD to the Menu Items list
      • click on SetLanguagePowerShell.py and 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.

      B R 2 Replies Last reply Mar 24, 2023, 5:51 AM Reply Quote 3
      • B
        BenHastingsFDSU @PeterJones
        last edited by Mar 24, 2023, 5:51 AM

        @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!

        1 Reply Last reply Reply Quote 1
        • R
          Riyas Aboobaker Abdul Rahman @PeterJones
          last edited by Apr 20, 2025, 8:32 AM

          @PeterJones Thanks!!

          1 Reply Last reply Reply Quote 0
          • D dr ramaanand referenced this topic on Apr 22, 2025, 9:08 AM
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors