Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show total line count status bar sublime text 3

Is there a code to put in the settings or a plugin that will show the total number of lines along the current line and column in the status bar in Sublime Text 3?

like image 640
Herman Toothrot Avatar asked Sep 20 '25 05:09

Herman Toothrot


2 Answers

The code to show the number of lines in the status bar is very simple, just get the number of lines

line_count = view.rowcol(view.size())[0] + 1

and write the to the status bar

view.set_status("line_count", "#Lines: {0}".format(line_count))

If you want to pack in a plugin you just need to write this in a function and call it on some EventListener. Create a plugin by clicking Tools >> Developer >> New Plugin... and paste:

import time
import sublime
import sublime_plugin

last_change = time.time()
update_interval = 1.5  # s


class LineCountUpdateListener(sublime_plugin.EventListener):
    def update_line_count(self, view):
        line_count = view.rowcol(view.size())[0] + 1
        view.set_status("line_count", "#Lines: {0}".format(line_count))

    def on_modified(self, view):
        global last_change
        current_change = time.time()
        # check if we haven't embedded the change in the last update
        if current_change > last_change + update_interval:
            last_change = current_change
            sublime.set_timeout(lambda: self.update_line_count(view),
                                int(update_interval * 1000))

    on_new = update_line_count
    on_load = update_line_count

This does in essentially call the command, when creating a new view, loading a file, and modifying the views content. For performance reason it has some logic to not call it on every modification.

like image 93
r-stein Avatar answered Sep 23 '25 20:09

r-stein


Goto menu -> find -> find in files.

Then select regex.

use this pattern to count line including white spaces in each line-

^(.*)$

To count the number of lines excluding white spaces, use pattern

^.*\S+.*$

you can specify if you exclude some directories of file types like

c:\your_project_folder\,*.php,*.phtml,*.js,*.inc,*.html, -*/folder_to_exclude/*

Note - Characters other than white spaces will get also count because they too have start and end with white space.

like image 27
Rohan Khude Avatar answered Sep 23 '25 20:09

Rohan Khude