Get current line in Sublime Text 3 plugin
Asked Answered
R

1

6

I'm writing a simple plugin for Sublime Text 3 and need to get the contents of the currently selected line. I can use

selection = sublime.Region(self.view.sel()[0].begin(), self.view.sel()[0].end())

to get the currently highlighted section, but is there a way to select or return the contents of the entire current line without manually selecting all of it?

The 'duplicate' example on this page does what I want, but seems to be broken in ST3. When I run it I get the error TypeError: run() missing 1 required positional argument: 'args'.

Resource answered 8/5, 2015 at 4:15 Comment(1)
the apiExecutive
M
12

I believe what you're after is view.substr(view.line(view.sel()[0]))

This will return the text of the current line.

Musclebound answered 8/5, 2015 at 4:46 Comment(1)
I believe you're right, sir! Thanks for that. I had to add self before each view... though, so it became self.view.substr(self.view.line(self.view.sel()[0]))Resource

© 2022 - 2024 — McMap. All rights reserved.