Microsoft Visual Studio Code extension integrating node.js module: opn
Opens files directly by default, or on your local web server using the default app set by the OS, or an app set by you.
Great for rapid prototyping!
Start VS Code.
From within VS Code press F1
, then type ext install
.
Select Extensions: Install Extension
and click or press Enter
.
Wait a few seconds for the list to populate and type Open File in App
.
Click the install icon next to the Open File in App
extension.
Restart VS Code to complete installing the extension.
Download the latest vscode-opn.vsix
from GitHub Releases.
You can manually install the VS Code extension packaged in a .vsix file.
Option 1)
Execute the VS Code command line below providing the path to the .vsix file;
code myExtensionFolder\vscode-opn.vsix
Depending on your platform replace myExtensionFolder\
with;
%USERPROFILE%\.vscode\extensions\
$HOME/.vscode/extensions/
$HOME/.vscode/extensions/
Option 2)
Start VS Code.
From within VS Code open the 'File' menu, select 'Open File...' or press Ctrl+O, navigate to the .vsix file location and select it to open.
The extension will be installed under your user .vscode/extensions folder.
Execute the extension with the keyboard shortcut;
Command
+ Alt
+ O
Ctrl
+ Alt
+ O
By default plain text based files will open directly in the app set by your OS.
To change this default behaviour you will need to edit 'Workspace Settings' or 'User Settings'.
From within VS Code open the 'File' menu, select 'Preferences', and then select either 'Workspace Settings' or 'User Settings'.
Options are set per 'language', not per file type, so for example setting options for the language 'plaintext', will change the behaviour of several file types including '.txt' and '.log'.
The minimum JSON to change the behaviour of a single language, e.g. html is;
"vscode-opn.perLang": {
"opnOptions": [
{
"forLang": "html",
"openInApp": "chrome"
}
]
}
Required
Type: string
Examples include;
Required
Type: string
Examples include;
Notes: The app name examples above are platform dependent and valid for an MS Windows environment. For Google's Chrome web browser for example, you would use google chrome
on OS X, google-chrome
on Linux and chrome
on Windows.
The following example sets all available options for html
and plaintext
languages;
"vscode-opn.perLang": {
"opnOptions": [
{
"forLang": "html",
"openInApp": "chrome",
"openInAppArgs": ["--incognito"],
"isUseWebServer": true,
"isUseFsPath": false,
"isWaitForAppExit": true
},
{
"forLang": "plaintext",
"openInApp": "notepad++",
"openInAppArgs": [],
"isUseWebServer": false,
"isUseFsPath": true,
"isWaitForAppExit": true
}
]
},
"vscode-opn.webServerProtocol": "http",
"vscode-opn.webServerHostname": "localhost",
"vscode-opn.webServerPort": 8080
Optional
Type: array
Examples include: ["--incognito", "-private-window"]
Notes: A string array of arguments to pass to the app. For example, --incognito
will tell Google Chrome to open a new window in "Private Browsing Mode", whereas -private-window
will do something similar in Mozilla Firefox.
Optional
Type: boolean
Default: false
Notes: If you set up a site on your local web server such as MS Windows IIS and your VS Code project folder is within the site root, you can open file URLs instead of URIs. This is useful for code that requires a server environment to run, such as AJAX. You will first need to update the vscode-opn default web server settings with your own.
Optional
Type: boolean
Default: false
Notes: During testing in an MS Win 10 environment both Notepad++ and MS WordPad did not support file URIs. This option will use the local file system path instead. This issue may affect other apps and other platforms too.
Optional
Type: boolean
Default: true
Notes: See node.js module opn option: wait for more info.
Required by the per language option: isUseWebServer
.
Optional
Type: string
Default: "http"
Notes: Enter a protocol, e.g. "http" or "https".
Optional
Type: string
Default: "localhost"
Notes: Enter the hostname or IP of your local web server.
Optional
Type: number
Default: 8080
Notes: Enter the port of your local web server.
Tested in MS Win 10 environment.
Works with plain text based file types including;
.html
.htm
.xml
.json
.log
.txt
Does not work with other file types including;
.png
.gif
.jpg
.docx
.xlsx
.pdf
Version 1.1.2
Date: 25 Feb 2016
Version 1.0.2
Date: 17 Feb 2016