Sublime Forum

Getting current filename and line number on keypress?

#1

Hi, I’m just trying to create a very basic plugin that executes on a keypress and requires the current selected filename and line number, I checked the API and saw that I can get this from sublime.View, but I can’t figure out how to access this class from a keypress (note - I have very little experience with Python, but am otherwise an experienced programmer).

Basically I created a python file, imported sublime_plugin and sublime and created a class which matched the command executed on a keypress. Now how do I access sublime.View ?

Thanks

0 Likes

#2

Nevermind, figured it out:

		view = sublime.Window.active_view(sublime.active_window())
		print view.file_name()
		(row,col) = view.rowcol(view.sel()[0].begin())
		print row + 1

Possibly not the best way, but it works.

0 Likes

#3

If your class extends sublime_plugin.TextCommand, then you can also access the active view as self.view (assuming the first argument to your run method is called self).

0 Likes