Edit html page in Sublime Text -> click some short key defined by ourselves -> html page is opened by Chrome
1. Open Sublime Text, menu Tools->New Plugins, then a python file is automatically created for us as below.
Then paste the following simple python source code:
import sublime, sublime_plugin
import webbrowser
class OpenBrowserCommand(sublime_plugin.TextCommand):
def run(self,edit):
window = sublime.active_window()
window.run_command('save')
url = 'file://' + self.view.file_name()
webbrowser.open_new(url)
The logic is quite easy: first save the currently edited file, get its path and open it via the default browser installed in your laptop.
Save it into <Sublime Text installation folder>/Packages/User. Rename the file as you wish, for example "open_browser.py".
2. Tools->Command Palette, then click "Preferences: Key Bindings - User":
paste the following source code:
[{ "keys": ["ctrl+shift+b"], "command": "open_browser" }]
it means you tell Sublime Text to execute your plugin "open_browser" when the combination key "ctrl+shift+b" is pressed.
Now it is done. After you press the keys you configured, the default browser will be opened by your plugin. Enjoy!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
21 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |