Sublime Forum

Display total line count

#1

This is just a simple thing so if it’s been mentioned before my searches weren’t finding it.

In the status bar where it currently says “Line ##, Column ##”, can this be changed to “Line ## of ###, Column ##” where ### is the total line count for the document? It’s just a handy bit of info to know at a glance :smile:

Cheers!

0 Likes

#2

I would like to see this too, and maybe also the total byte count of the file.

Other editors I’ve used would even show the decimal and hex value of the current character, which would be cool to have.

0 Likes

#3

Yes, for sure! :smile:

Quite interesting! If it doesn’t make the status bar look too crowded, then I say go for it.

0 Likes

#4

Of course, my feature suggestion about that is to have a user editable status format with replaceable tokens:

  statusFormat  "Line %line of %lines, Col %col of %cols, %bytes bytes - %char  %dec  %hex"

For example. :smile: Then Sublime Text can come with a default standard format, and people can customize it as they like.

0 Likes

#5

[quote=“ToddFiske”]

Of course, my feature suggestion about that is to have a user editable status format with replaceable tokens:

  statusFormat  "Line %line of %lines, Col %col of %cols, %bytes bytes - %char  %dec  %hex"

For example. :smile: Then Sublime Text can come with a default standard format, and people can customize it as they like.[/quote]

+1, I like that :smiley:
even though is possible to do all this with a plugin, I would like it to be default.

0 Likes

#6

I’m another one who’d appreciate line count. Also I’d quite like the encoding included[1], too! :smile: I’m only generally concerned whether or not it’s UTF-8 or UTF-16.

Like others I am keen to avoid a cluttered status bar, and I appreciate this could be done via a plugin but it’s all about getting the best out-of-box experience. Especially when the plugins have such a steep learning curve.

[1] I know it currently shows it if you hover over the tab, but I’d certainly vote for it being ever present.

0 Likes

#7

As EJ12N said, you can do this via a plugin.

Here’s a working sample to get you started:

[code]import sublime, sublimeplugin

class CustomStatusBar(sublimeplugin.Plugin):
def onSelectionModified(self, view):
if not view.hasNonEmptySelectionRegion():
line, column = view.rowcol(view.sel()[0].begin())
totalLines = len(view.lines(sublime.Region(0L, view.size())))
msg = ‘Line %d of %d, Column %d’ % (line, totalLines, column)
sublime.statusMessage(msg)
else:
sublime.statusMessage(’’) # restore default status msg[/code]

Or you can use something like this instead (less pretty, but more plugin friendly):

view.setStatus("totalLines", "Total lines: %d" % totalLines)
2 Likes

#8

I’ve been using this plugin for a while and I keep finding it a bit flaky. It only shows me the line count when I change the location of the cursor, but if I switch to a different window and then switch back, it still displays the old “Line X, Column Y” message until I change the cursor location again. It also reverts after you let it sit for ten seconds or so without any interaction.

I would like to have the total line count displayed at all times. Is there a way I can also add this behaviour when the document becomes visible/selected? I am not that familiar with the event architecture for use by plugins :smile:

I also had to add 1 to all of the displayed values because the variables used by the plugin are all zero-based.

         msg = 'Line %d of %d, Column %d' % (line + 1, totalLines + 1, column + 1)
0 Likes

#9

You can see the callbacks available to plugins at sublimetext.com/docs/api-ref … gin.Plugin , in this case you’ll want to use the onActivated callback.

0 Likes

#10

Okay, got that working. Thanks! :smile: However, how do I stop the old statusbar format (“Line ##, Column ##”) from returning after several seconds of no interaction? Is there a way I can interrupt that timeout?

0 Likes

#11

You can used view.setStatus() to assign a persistent status message with a view - see the API reference for details. You’ll want something along the lines of (untested, btw):

import sublime, sublimeplugin

class CustomStatusBar(sublimeplugin.Plugin):
    def onModified(self, view):
        totalLines = len(view.lines(sublime.Region(0L, view.size())))
        msg = '%d lines' % (totalLines)
        sublime.setStatus('totalLines', msg)

    def onLoaded(self, view):
        self.onModified(view)
3 Likes

#12

Does anyone know any way to do this? Even if it isn’t in the status bar, though that would be ideal. It is something all the other editors I have used/tried tend to do, and something I find very useful.

0 Likes