Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
open_file_at_cursor sublime command
cd ~/.config/sublime-text-2/Packages/User/
curl -O

Open keyboard bindings file, and add a line to it

    { "keys": ["alt+o"], "command": "open_file_at_cursor" } // this one
import sublime, sublime_plugin
import os.path, string
import re
VALID_FILENAME_CHARS = "-_.() %s%s%s" % (string.ascii_letters, string.digits, "/\\")
filename_re = re.compile(r'[\w/\.-]+')
class OpenFilenameUnderCursor(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
# Find anything looking like file in whole line at cursor
whole_line = self.view.substr(self.view.line(region))
row, col = self.view.rowcol(region.begin())
while col >= len(whole_line) or whole_line[col] in VALID_FILENAME_CHARS:
col -= 1
m =, col)
if m:
filename =
print "Opening file '%s'" % (filename)
print "No filename discovered"

This comment has been minimized.

Copy link

shivan commented Sep 5, 2018

in ST3: replace "open_file_at_cursor" in keyboard bindings with "open_filename_under_cursor".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.