Stocki - 2013-08-23

Hello all,

I was looking for a script to increase or decrease (CSS) numbers with hotkeys in NPP like in Google Chrome Developer Tools.
I found nothing so I created a script and wrote the following tutorial. :)

What you will need:
- Notepad++ (of course) :)
- NppExec Plugin

  1. Press F6 to open the Execute... window and insert this script:
    npp_console disable
    set modify = 1
    set cw = $(CURRENT_WORD)
    set num ~ $(CURRENT_WORD)+0
    set suffix_pos ~ strlen $(CURRENT_WORD)
    set is_nan ~ strfind $(num) "+"
    // Is there some suffix, eg. px, mm...?
    if $(is_nan) == -1 goto skipSuffix
    set suffix_pos ~ -2 // px, in, mm etc.
    :skipSuffix
    // Let's modify our CURRENT_WORD! (increase/decrease)
    set num ~ substr 0 $(suffix_pos) $(cw)
    set num ~ $(num)+0
    set is_nan ~ strfind $(num) "+"
    if $(is_nan) != -1 goto Done // NaN!
    set res ~ $(num)+$(modify)
    if $(res) < 0 goto Done // Better safe than sorry :)
    // Add suffix to our modified CURRENT_WORD!
    set suffix = // Empty string
    if $(suffix_pos) > 0 goto noSuffix
    set suffix ~ substr $(suffix_pos) - $(cw)
    :noSuffix
    sel_settext $(res)$(suffix)
    :Done
    npp_console enable
  1. Save as 'Increase +1' or as you wish.
  2. Replace 'set modify = 1' with 'set modify = -1'.
  3. Save as 'Decrease -1'. Now you can close the Execute... window with Cancel. To test the script type '43px' in NPP and press F6 and OK. Wow, almost there. :)
  4. Open Plugins > NppExec > Advanced Options... window. Add/modify the 'Increase +1' option from the Associated script list. Press OK then repeat this with 'Decrease -1'.
  5. Restart Notepad++.
  6. Click Run > Modify Shortcut/Delete Command... > Plugin Commands tab. Find 'Increase +1' and double click on Shortcut box. I'm using 'Alt + Up' hotkeys.
  7. Repeat this with the 'Decrease -1' and 'Alt + Down' Shortcut.

That's all. If you type '123' and press Alt + Up/Down you can increase/decrease the number. Cool. :)

+1. You can replace 'set modify = 1' with 'set modify = 10' and associate 'Ctrl + Alt + Up' hotkeys for bigger steps.