Giter VIP home page Giter VIP logo

obsidian-open-vscode's Introduction

Open in VSCode

This plugin for Obsidian makes a ribbon button and two commands to open your vault as a Visual Studio Code workspace:

  • open-vscode: Uses child_process to launch VSCode with the code command. Currently, this is the command bound to the ribbon button.
  • open-vscode-via-url: Open VSCode using a vscode:// URL (Windows users, please see notes regarding the UX of this command)

It's functionality is probably made redundant now using the Shell commands and Customizable Sidebar (or Buttons) plugins, but it'll be maintained for the foreseeable future.

You can use VSCode for various purposes with your vault, such as for git version control, markdown formatting with Prettier, linting with markdownlint, mass formatting files and more.

video showcase

The icons work with light and dark mode.

light and dark

You can also use it as a command and assign hotkeys to it. You can disable the ribbon button in settings. command

Settings

  • Display Ribbon Icon
  • Ribbon opens via code (can alteratively open via URL method)

Template for executing the code command

You can template the command opening VSCode however you like with its provided command line arguments. This way you can technically launch any command you set, so take caution. Potential use cases include opening workspaces with .code-workspace files (e.g. for Dendron), opening specific files, folders, etc.

Note that on MacOS, a full path to the VSCode executable is required (generally "/usr/local/bin/code").

You can use the following variables: {{vaultpath}} (absolute), {{filepath}} (relative), {{folderpath}} (relative). The default template is code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}", which opens the current file (if there is one) in the workspace that is the vault's root folder. This gets expanded to be executed in your shell as code "C:\Users\YourUser\Documents\vault" "C:\Users\YourUser\Documents\vault/Note.md", for example.

Settings for open-vscode-via-url

On some systems, this may be faster than using the child_process approach.

  • Open file

    Open the current file rather than the root of the Obsidian vault.

  • Path to VSCode Workspace

    Defaults to the {{vaultpath}} template variable. You can set this to an absolute path to a ".code-workspace" file if you prefer to use a Multi Root workspace file

  • Open VSCode using a vscode-insiders:// URL

The first time you use the URL method for opening, VSCode displays a confirmation dialog (that you just can hit enter on) for security reasons. See this issue for more infomation.

Caveats regarding the URL command for Windows users

TLDR; We recommend that Windows users prefer the open-vscode command (and not the URL one).

Due to security updates in VSCode, the user experience of using opening VSCode via URL comes with some known issues!

On Windows, when opening via URL, you are prompted to allow VSCode to access the file. At present there's no option in VSCode to whitelist safe locations (ie your Obsidian vault), so you get this dialog every time ☹️.

Worse, if you are opening via URL, and have toggled the "Open File" setting on, then VSCode will attempt to open a second instance of VSCode, and will warn that there's another instance of Code running but not responding.

If this issue affects you, please consider watching and voting for the following VSCode issues:

Installation

You can install the plugin via the Community Plugins tab within the Obsidian app.
Here's the plugin in Obsidian's Community Plugins website.
You can install the plugin manually by copying a release to your .obsidian/plugins/open-vscode folder.

Development

This plugin follows the structure of the Obsidian Sample Plugin, see further details there.
Contributions are welcome.

If pjeby/hot-reload is installed, activated, and open-vscode is registered with hot-reload, then extra logging and DX commands to refresh settings are activated.

Credits

Original plugin by NomarCub.
If you like this plugin you can sponsor me here on GitHub: Sponsor NomarCub, on Ko-fi here: Buy Me a Coffee at ko-fi.com, or on PayPal here: Paypal.

Toggle ribbon setting by ozntel.
UseURL: open file in workspace feature and restructure by ptim.

Thank you to the makers of the DEVONlink plugin, as it was a great starting point for working with ribbon icons in Obsidian. The icon is from Simple Icons (SVG).

obsidian-open-vscode's People

Contributors

nomarcub avatar ptim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

obsidian-open-vscode's Issues

Please add variable for current folder

Hi,

Would it be possible to add in a variable for the folder of the currently opened file? A common use case I have that I have a file open in a directory and actually I want to open that whole directory (not the whole vault) in VScode. I think this could easily be done by splitting out {{filepath}} into {{path}}/{{file}} (if possible)

Console error at startup with hot-reload

The error below appears in the dev console at startup if you have the hot-reload plugin enabled, but it hasn't loaded yet. (There should be a ? after app.plugins.plugins["hot-reload"], before the .enabledPlugins.)

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'enabledPlugins') at OpenVSCode.onload (plugin:open-vscode:146:103)

Plugin doesn't work on Linux with Flatpak

Such as related on #3, I click on ribbon button and nothing happens.

System info:

  • OS: Fedora release 39 (Thirty Nine) x86_64
  • Kernel: 6.5.12-300.fc39.x86_64
  • DE: GNOME 45.1 (x.org)
  • WM: Mutter

Obsidian

  • Obsidian version: 1.4.16
  • plugin version: 1.2.1

VSCode

  • Version: 1.84.2
  • hash: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
  • Date: 2023-11-09T10:50:47.800Z
  • Electron: 25.9.2
  • ElectronBuildId: 24603566
  • Chromium: 114.0.5735.289
  • Node.js: 18.15.0
  • V8: 11.4.183.29-electron.0
  • SO: Linux x64 6.5.12-300.fc39.x86_64
  • packaging format: rpm

Plugin doesn't open my vault in VS Code

I've downloaded and enabled the plugin, but when I either click the ribbon or select command from the command palette, Obsidian freezes for a couple of seconds then nothing happens.
I'm on MacOS Big Sur 11.4, using the latest version of Obsidian and the latest version of the plugin. VS Code itself works fine for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.