Adding leading zeros or additional leading space for line numbers
-
I’m curious if there is a way to add leading zeros or additional leading space for line numbers.
I have a situation where I have a file that has nearly 3000 lines. From 1 to 999, the line numbers are properly padded. But once I reach line 1000, the area expands to accommodate the larger number, shifting the main area to the right slightly, which is a bit annoying as I scroll and view the file.
I made an example gif of what is occurring.
Just wondering if there is some setting or secret file in Notepad++ I can modify. Currently I am using version 7.5.7.
-
I don’t think so and it seems that changing width via a scripting language isn’t successful either. Seems you need to open an issue at github but as far as I remember there has one been opened recently. Please check before reopen another one.
-
@codenotworking said:
…once I reach line 1000, the area expands to accommodate the larger number, shifting the main area to the right slightly, which is a bit annoying as I scroll and view…
There’s a workaround proposed by xylographe that works for this, and it is found here: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5670
-
Hello, @codenotworking, @ekopalypse, @alan-kilborn, and All,
Many thanks, Alan, for pointing out this GitHub article !
So, to summarize, as the predefined STYLE_LINENUMBER is numbered
33
( Refer below )https://www.scintilla.org/ScintillaDoc.html#StyleDefinition
And, from the two links, below, as we can, obviously, choose any string, in order to calculate the LINENUMBER margin
https://www.scintilla.org/ScintillaDoc.html#SCI_SETMARGINWIDTHN
https://www.scintilla.org/ScintillaDoc.html#SCI_TEXTWIDTH
Let’s use the simple format “
12345678
”, which allows number lines between values1
and99,999,999
(8
digits )Hence, the two commands, that I’ve personally tested :
-
With the Python script :
editor.setMarginWidthN(0, editor.textWidth(33, "12345678"))
-
With the Lua script :
editor.MarginWidthN[0] = editor:TextWidth(33, "12345678")
Note that if your current file contains more than
99,999,999
lines, any digit, on the left, is, then, truncated !So, the transition between the two lines
99,999,999
and100,000,000
, bookmarked would look like, as below :99999999 ● ( Line 99,999,999 ) 00000000 ● ( Line 100,000,000 )
Best Regards,
guy038
-
-
Hi, All,
Regarding my previous post, I’ve noticed that, after running the script commands, if you increase the zoom factor, significantly, you may miss the leftmost number digit :-((
In that case, just re-run the appropriate script command, with the same parameters !
Note that, with the native N++ numbering; this is done automatically ;-))
Cheers,
guy038
-
@guy038 said:
…zoom…
True, but this would be a rare thing (for most people). Much rarer than that little visual blip that occurs as you move through line # 1000.
-
@guy038 said:
…zoom…
But if it is really a factor for you, you could put it in a zoom-notify :
try: zoom_notify_installed except NameError: def callback_sci_ZOOM(_): editor.setMarginWidthN(0, editor.textWidth(33, "12345678")) editor.callback(callback_sci_ZOOM, [SCINTILLANOTIFICATION.ZOOM]) zoom_notify_installed = True editor.setMarginWidthN(0, editor.textWidth(33, "12345678"))
(for Pythonscript; I don’t know the Luascript way of doing that)