As far as I’m aware the only way to find all of the views that represent the same file is to compare the buffer_id()
value of all views (either in a particular window
or among the results of sublime.windows()
); that will be unique among all views that represent the same file.
For example, this command will print to the console the list of view
objects in the current window that represent the same file as the view
that the command is executed in:
import sublime
import sublime_plugin
def views_for_file(window, file_name):
view = window.find_open_file(file_name)
if view is None:
return None
return [v for v in window.views() if v.buffer_id() == view.buffer_id()]
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
print(views_for_file(self.view.window(), self.view.file_name()))
def is_enabled(self):
return self.view.file_name() is not None
Similarly if you already have a view
(as the command here does) you could just compare the buffer_id()
directly without having to do a lookup.