Skip to content

Instantly share code, notes, and snippets.

@glaucocustodio
Forked from jbjornson/SwitchToFile.py
Created November 14, 2012 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaucocustodio/4072953 to your computer and use it in GitHub Desktop.
Save glaucocustodio/4072953 to your computer and use it in GitHub Desktop.
Show a input panel to switch to a currently open file
# -------------------------------------------
# You will need to create a key mapping for this, something like:
# { "keys": ["alt+e"], "command": "switch_to_file" }
# -------------------------------------------
class SwitchToFileCommand(sublime_plugin.WindowCommand):
def run(self):
self.display_list = []
self.views = []
for view in self.window.views():
path = view.file_name()
if view.is_scratch():
name = view.name()
path = '(view id = %d)' % (view.id())
elif not path:
name = 'Untitled'
path = '(view id = %d)' % (view.id())
else:
name = os.path.split(path)[1]
self.display_list.append([name, path])
self.views.append(view)
self.window.show_quick_panel(self.display_list, self.switch_to_view, False)
def switch_to_view(self, index):
if index >= 0 and len(self.views) > index:
self.window.focus_view(self.views[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment