mikelovelyuk
mikelovelyuk

Reputation: 4152

Print Current Line number in Sublime

Is there a key-combination to print out the current line number?

This would be really useful in conjunction with the multiple selection method (cmd+D).

Upvotes: 2

Views: 1577

Answers (1)

Gerard Roche
Gerard Roche

Reputation: 6381

I don't think there is a key binding or command do what you want, but I'm I'm unsure what it is that you mean by printing current line numbers in Sublime.

This is probably not at all what you want, but I'll leave it here for a while before I delete it. It might help you write a custom command for what you want.

Command

import sublime_plugin

class InsertLineNumberCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        for sel in self.view.sel():
            line_begin = self.view.rowcol(sel.begin())[0]
            line_end = self.view.rowcol(sel.end())[0]

            self.view.insert(edit, sel.end(), str(line_begin + 1))

Key Binding:

{
    "keys": ["ctrl+i"],
    "command": "insert_line_number"
}

Usage

1: 
2: fizz|buzz
3:

Where | is the cursor, pressing ctrl+i:

1: 
2: fizz2|buzz
3:

With a multiple selection:

1: 
2: |fizz|2
3: buzz
4:
5: |fizz|5
6: buzz
7:

Upvotes: 11

Related Questions