In notepad++ change tab size instantly

2019-01-15 21:33发布

问题:

I'm using notepad++ (v6.5.3) and I constantly have to change the size of the tab for viewing some results. Not that it's taking me a lot of time to do it manually everytime, but it would be great if I could optimize that.
Is there a way to do so? Would a macro be the solution, or are they just for typing stuff?

Thanks a lot!

回答1:

Ok, there's an easy way how you can achieve this - I have tested it right now:

  1. Install AutoHotKey (or start portable version which runs without installation)
  2. In Windows 7 and above, ensure you launched AutoHotKey as Administrator (otherwise you get inconsistencies in its behavior) - if not sure, exit it and restart it as administrator
  3. Right click Autohotkey tray icon and select Edit This Script
  4. Import the macro below this list at the end of the AutoHotKey script file and save the file
  5. Right click Autohotkey tray icon and select Reload This Script.
    –– This was end of general steps, now let's go with your macro: ––

  6. In N++, display Preferences window and press its Close button1 at the bottom (NOT at the top-right corner)

  7. Now you can use shortcuts Win+F2 and Win+F3 to switch different tab sizes instantly

    SendMode Input
    DetectHiddenWindows, On
    SetTitleMatchMode, RegEx

    ;--------------------------------- Hotkeys for Notepad++ only
    #IfWinActive ahk_class Notepad\+\+

    #F2::Send {F10}{Right 6}{Down}{Enter}{Tab 2}{Space}16{Enter}{Tab 3}{Space}
    #F3::Send {F10}{Right 6}{Down}{Enter}{Tab 2}{Space}4{Enter}{Tab 3}{Space}

    #IfWinActive

1) Important: N++ user experience provided in dialog boxes is absolutely terrible. There are no anchors where you can fix focus when using keyboard. Thus you always need to perform step 4 manually when leaving Preferences dialog box otherwise the macros would send keys into incorect window page OR at correct page but incorrect control. Preferences dialog window remembers selected page and control. Macros I created for you therefore assume that correct page is already listed and button Close was recently focused.
Good news is Notepad++ windows with this weird behavior are rare exception from general user experience. In other places in N++ (or in other apps) where user interface components (menus, dialogs etc.) always start from the same point you do not need any special precautions like the one in step 4.

Adjust the macros as you like:

  • you can create more of them
  • you can adjust the numbers "16" and "4" typed into tab size input box
  • you can change shortcut keys to something else
  • you can replace sending keys with sending mouse clicks at desired screen/window positions
  • you can achieve many other useful shortcuts in N++ and in all other apps – check AHK deeper!