• Stars
    star
    272
  • Rank 150,365 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Open the contents of your current view/tab in a web browser

Sublime Text - View In Browser

View In Browser is a Sublime Text plugin that will open whatever is in your current view/tab. If the file current open is new and has not been saved a temporary file is created (in your default temp directory for your OS) with the extension of .htm and your browser will open it. However if the current open file is saved and has a name this plugin will open it in whatever you have set to handle its type.

By default the keystroke assigned to this plugin is CTRL + ALT + V.

Installation

Using the Sublime Text Package Control plugin (http://wbond.net/sublime_packages/package_control) press CTRL + SHIFT + P and find Package Control: Install Package and press Enter. Find this plugin in the list by name View In Browser.

Configuring Browsers

By default this plugin will open files in Firefox. You can configure it to open using another browser of your choice. To do this, choose Settings - User from Preferences > Package Settings > View In Browser.

The browser you wish to use to open files is set in the key named browser. The following is a list of browsers configured for use out of the box.

  • Firefox - Mac OS, Linux, Windows
  • Chrome - Mac OS, Linux, Windows
  • Chrome64 - Windows
  • Yandex - Windows
  • Safari - Mac OS
  • Internet Explorer - Windows
  • Chromium - Linux

Other Browsers

View In Browser also provides key bindings to open your current view in browser other than your browser setting. Below is a listing of the keys and what browser open with those key bindings.

  • CTRL + ALT + F - Firefox
  • CTRL + ALT + C - Chrome
  • CTRL + ALT + I - Internet Explorer
  • CTRL + ALT + S - Safari

Like any other key binding in Sublime these can be changed. Below is an example of the key configuration. You can remap these in your User key bindings configuration file.

[
    { "keys": [ "ctrl+alt+v" ], "command": "view_in_browser" },
    { "keys": [ "ctrl+alt+f" ], "command": "view_in_browser", "args": { "browser": "firefox" } },
    { "keys": [ "ctrl+alt+c" ], "command": "view_in_browser", "args": { "browser": "chrome" } },
    { "keys": [ "ctrl+alt+i" ], "command": "view_in_browser", "args": { "browser": "iexplore" } },
    { "keys": [ "ctrl+alt+s" ], "command": "view_in_browser", "args": { "browser": "safari" } }
]

Windows Considerations

One of the things you may notice in the Windows configuration for chrome is a variable in the command path that looks like: %Local AppData%. This is a reference to your Windows installation's AppData folder in your user profile directory. There is a variable there because this value will differ for each user on your computer, and Chrome installs to your AppData folder.

Here is a list of supported variables:

  • AppData - Your main application data folder for your profile (usually roaming)
  • Personal - Your documents location
  • Desktop - The path to your Desktop location (may be unreliable)
  • Start Menu - The path to your Start Menu items location
  • Local AppData - Your local application data folder for your profile
  • My Video - Path to your videos location
  • My Pictures - Path to your pictures location
  • My Music - Path to your music location

Note that many of these are not terribly useful for determining browser location, unless you have decided to install Firefox in your My Music folder.

Configure to View on Local Server

The View In Browser plugin also supports the ability to view files in the context of a local server. So if you have a local Apache, Tomcat, or some other server application running you can configure this plugin to open your file prefixed with a URL.

To configure this the View In Browser plugin reads the configuration of your currently loaded project. You can edit a project file by opening the sublime-project file by choosing Project -> Edit Project. In your project file you will need to specify two things:

  • baseUrl - The root URL to prefix files with
  • basePath - The base path where your site/application lives

Here's how that looks.

{
	"folders":
	[
		{
			"path": "/home/<username>/code/python/my-cool-website"
		}
	],
	"settings": {
		"sublime-view-in-browser": {
			"baseUrl": "http://localhost:8080",
			"basePath": "/home/<username>/code/python/my-cool-website"
		}
	}
}

Notice the key named settings which is a dictionary that contains another key named sublime-view-in-browser. This is where you will put your baseUrl and basePath settings.

Now when you activate View In Browser your file will open with the HTTP protocol instead of the FILE protocol.

Change History

  • 03/11/2016:
    • Fix issue where parenthesis in paths would cause a failure to load. Solves #52
  • 10/06/2014:
    • Rewrite for version 2.0.0
    • Using subprocess instead of webbrowser. Seems to solve #19
    • Smaller, simplier sublime-settings file
  • 05/15/2014:
    • Current view only saves if there are modifications
  • 07/03/2013:
    • Changes to support Sublime Text 3 and Python 3
  • 06/15/2013:
    • Backslashes in Windows are now converted to forward slashes when using a local server configuration. Closes #16
  • 04/16/2013:
    • Added support for muliple paths per browser configuration (jadient #14)
  • 03/08/2013:
    • Avoid loading Windows special folder references when on a Mac
    • Added Mac Chrome to the supported browsers list
  • 02/18/2013:
    • Added ability to use Windows special folder references to browser commands. Closes #10
  • 01/30/2013:
    • All settings for this plugin now live in the file View In Browser.sublime-settings. This allows for a user to override them in their User directory. The old settings.json file is no longer used.
  • 01/28/2013:
    • Merged in change from imaginationac to remove menu nesting
  • 12/26/2012:
    • Added Linux Chromium to the supported browsers list
  • 11/01/2012:
    • Altered command to open Safari on Mac
    • When invoked the current view is auto-saved
  • 10/25/2012:
    • New settings.json file to map browser/commands to OSes
    • Plugin will use the specified browser to open files, or default to OS default when browser is unsupported
    • Addressed encoding issue when calling open_new_tab
    • Added ability to specify and respect local server config per project
  • 05/21/2012:
    • Temp file only created if view is unsaved
  • 05/18/2012:
    • Initial code

Contributors

License

The MIT License (MIT) Copyright (c) 2012 Adam Presley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

sample-ini-parser

Sample project for a blog series on lexing and parsing
Go
35
star
2

bottlepy-bootstrap

My skeleton Bottle (Python) application bootstrapper
Python
32
star
3

sublime-js-minify

Sublime JavaScript Minifier
Python
14
star
4

golang-webapp-starter-kit

My webapp/microservice starter kit for Go
Go
7
star
5

sublime-debugkiller

Find debug statements unintentionally left behind in your code
Python
7
star
6

multiselect

Simple multiselect widget. No jQuery required!
JavaScript
7
star
7

sqlBackupRestorePS

My simple MS Sql Server backup and restore Powershell script
PowerShell
6
star
8

mailslurper-go

Simple mail server that slurps mail into oblivion!
JavaScript
5
star
9

code-standards

Documents of coding standards I follow for various languages
5
star
10

cf-basis

A small ColdFusion framework
ColdFusion
5
star
11

cordovareloader

Cordova live reloader for the browser
Go
3
star
12

sublime-fillcfquery

A Sublime Text plugin that takes query statements in ColdFusion debug output and fills in CFQUERYPARAMs
Python
3
star
13

logrusviewer

A tool to view logs generated by Logrus (the excellent Golang logger library)
JavaScript
3
star
14

sigint

CTRL+C handler for my command line Go apps
Go
3
star
15

BootstrapPlus

Enhancements and wrappers for the Twitter Bootstrap jQuery plugins
JavaScript
3
star
16

swapi-go

Go bindings for the SWAPI!
Go
2
star
17

webframework

Some Golang Web Framework helpers
Go
2
star
18

cflogparser

ColdFusion command-line log parser
Groovy
2
star
19

codedayspa

A spa day for your JSON, web services, and REST services. Beautify!
ColdFusion
2
star
20

GoHttpService

HTTP methods I use a lot
Go
2
star
21

adam-json-formatter

Adam's JSON Formatter
JavaScript
2
star
22

cfpowertools

CF PowerTools is a set of components written in Groovy to make easier various tasks for manipulating arrays, structures, strings, and more for CFML.
JavaScript
2
star
23

vanilla-todo-2021

Code for an article on Medium about making a todo app in vanilla JavaScript
JavaScript
2
star
24

gofavigrab

Go Favicon Grabber
Go
1
star
25

minitextindexer

A small, fast text indexer
Go
1
star
26

golangdb

Small database abstraction for Go
Go
1
star
27

sublime-mxunit-runner

Sublime Text plugin to run ColdFusion MXUnit tests
Python
1
star
28

spaceinvaders

A Space Invaders game written in Go
Go
1
star
29

cf-basis-i18n-plugin

I18N plugin for CF-Basis
1
star
30

YAOF

Yet Another Observer Framework for JavaScript
JavaScript
1
star
31

bottle

bottle.py is a fast and simple micro-framework for python web-applications.
Python
1
star
32

sublime-blogify

Sublime Text plugin to make source code more blog friendly
Python
1
star
33

golang-sorting-example

Example of custom sort in Go
Go
1
star
34

unplexing-grails

Unplexing.com in Grails
JavaScript
1
star
35

mailslurper

Simple mail server that slurps mail into oblivion!
JavaScript
1
star
36

vAccordousel

A jQuery plugin for a vertical accordion carousel.
JavaScript
1
star
37

cf-basis-timezoneUtils-plugin

A simple timezone utility plugin for the Basis framework
ColdFusion
1
star
38

cfbarbecue

CFBarbecue is a ColdFusion wrapper for the Barbecue Barcode Java library, and a little more.
JavaScript
1
star
39

skeleton-railo-bootstrap-fw1

A skeleton Railo+Bootstrap+FW1 application
ColdFusion
1
star
40

sublime-cf-js-log-finder

A console/cfdump/cfabort finder for Sublime Text 2
Python
1
star
41

ANT-Mass-Minify

Mass JS and CSS minification task for ANT
Perl
1
star
42

Blast-for-Basis

Tools for building CFML applications in the Basis framework
ColdFusion
1
star
43

SimpleJSONMarshaller

A Grails plugin for easy JSON marshaling of domain object
Groovy
1
star
44

Open-Group-Manager

An application designed to manage a group like an open source project.
ColdFusion
1
star
45

lexer

A simple lexer framework
Go
1
star
46

apMessageBox

A wrapper for ad-hoc message boxes around jQuery UI
JavaScript
1
star
47

minifyfs

Implementation of http.FileSystem that minifies JS and CSS. Useful for static asset embedding compilers. Horribly inefficient
Go
1
star
48

mygitpy

Python functions wrapping Git command line
Python
1
star