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
Press F6 to open the Execute... window and insert this script:
npp_consoledisable
setmodify=1setcw=$(CURRENT_WORD)setnum~$(CURRENT_WORD)+0
setsuffix_pos~strlen$(CURRENT_WORD)setis_nan~strfind$(num)"+"//Istheresomesuffix,eg.px,mm...?
if $(is_nan) == -1 goto skipSuffixsetsuffix_pos~-2//px,in,mmetc.
:skipSuffix
//Let'smodifyourCURRENT_WORD!(increase/decrease)setnum~substr0$(suffix_pos)$(cw)setnum~$(num)+0
setis_nan~strfind$(num)"+" if $(is_nan) != -1 goto Done // NaN!setres~$(num)+$(modify) if $(res) < 0 goto Done // Better safe than sorry :)//AddsuffixtoourmodifiedCURRENT_WORD!
setsuffix=//Emptystring
if $(suffix_pos) > 0 goto noSuffixsetsuffix~substr$(suffix_pos)-$(cw):noSuffix
sel_settext$(res)$(suffix):Done
npp_consoleenable
Save as 'Increase +1' or as you wish.
Replace 'set modify = 1' with 'set modify = -1'.
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. :)
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'.
Restart Notepad++.
Click Run > Modify Shortcut/Delete Command... > Plugin Commands tab. Find 'Increase +1' and double click on Shortcut box. I'm using 'Alt + Up' hotkeys.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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.