Sublime Forum

Open file by a hot key

#1

How can I do this?

I put

	{ "keys": "f1"], "command": "open_file", "args": {"filename": "index.php"} }

I struggle with sublime API and open_file but nothing works and I can’t debug it. It always returns nothing.

For example, I thought it will work. I was wrong. =)

import sublime, sublime_plugin
import os

class open_fileCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_dir',
            os.path.join(sublime.packages_path(), 'User'))
        v.set_syntax_file('Packages/JavaScript/JSON.tmLanguage')
        v.set_name('untitled.sublime-build')

        template = """{
	"cmd": "${0:make}"]
}
"""
        v.run_command("insert_snippet", {"contents": template})

0 Likes

#2

Should be something like this:

  { "keys" : "f1"], "command": "my_open_file", "args": {"file" : "index.php"}}
import sublime, sublime_plugin
import os.path

class MyOpenFileCommand(sublime_plugin.WindowCommand):
    def run(self, file):
        dir_name = os.path.join(sublime.packages_path(), 'User')
        self.window.open_file(os.path.join(dir_name, file))
0 Likes

#3

Wow!
This is really cool. Thank you so much!

0 Likes