Git Product home page Git Product logo

obsidian-bridge.nvim's Introduction

๐Ÿง˜ Purpose

Obsidian is great, but it doesn't offer the first-class Neovim experience that some of us just can't seem to do without. In the scenario where we edit notes in Neovim and view them rendered in Obsidian we would also like Obsidian to automatically follow navigation we do on the Neovim side.

That's where obsidian-bridge.nvim comes in. It mirrors navigation events in Neovim in the Obsidian app. If you open a note in Neovim the Obsidian App will show the same note automatically. If you navigate to another one or navigates to another Neovim buffer, the Obsidian app will show the corresponding note.

This is accomplished by leveraging the Local REST API plugin for Obsidian.

๐ŸŽฅ Demo

demo

๐Ÿง‘โ€๐Ÿ”ง Installation

  1. Make sure you have curl installed on your system and available on your PATH.

  2. Install and enable the Local REST API community plugin in Obsidian. Important: The default configuration of obsidian-bridge.nvim will try to connect to the non-encrypted server variant so remember to enable that in the Local REST API settings if you want to use it.

  3. Set the environment variable OBSIDIAN_REST_API_KEY to the API key found in the Local REST API settings within Obsidian, for example:

export OBSIDIAN_REST_API_KEY=<your api key, without the brackets>
  1. Install obsidian-bridge.nvim, here are examples for some popular package managers:
Lazy
{
  "oflisback/obsidian-bridge.nvim",
  dependencies = { "nvim-telescope/telescope.nvim" },
  config = function() require("obsidian-bridge").setup() end,
  event = {
    "BufReadPre *.md",
    "BufNewFile *.md",
  },
  lazy = true,
  dependencies = {
    "nvim-lua/plenary.nvim",
  }
}
Packer
require('packer').startup(function()
    use {
      'oflisback/obsidian-bridge.nvim',
      requires = { "nvim-telescope/telescope.nvim" }
      config = function() require('obsidian-bridge').setup() end
      requires = {
        "nvim-lua/plenary.nvim",
      },
    }
end)
vim-plug
Plug 'nvim-telescope/telescope.nvim'
Plug 'oflisback/obsidian-bridge.nvim'
  Plug 'nvim-lua/plenary.nvim'

โš™๏ธ Configuration

If no config parameter is provided to the setup function this default configuration will be used:

{
  obsidian_server_address = "http://localhost:27123"
  scroll_sync = false -- See "Sync of buffer scrolling" section below
}

Pass a config table as parameter to the setup function to provide an alternative server address, for example to use with lazy:

{
  "oflisback/obsidian-bridge.nvim",
  dependencies = { "nvim-telescope/telescope.nvim" },
  config = function() require("obsidian-bridge").setup({
    obsidian_server_address = "https://localhost:27124"
  }) end,
  event = {
    "BufReadPre *.md",
    "BufNewFile *.md",
  },
  lazy = true
}

โŒจ๏ธ Commands

  • :ObsidianBridgeDailyNote takes you to your daily note or generates it for you if it doesn't already exist. Make sure to have the Daily Notes core plugin enabled in Obsidian for this to work. Since it internally uses the Daily Note plugin to create the note for you, templates will work the same way as if it was triggered from within Obsidian.
  • :ObsidianBridgeOpenGraph opens the graph view in Obsidian, as long as the Graph core plugin is enabled.
  • :ObsidianBridgeOpenVaultMenu opens the Obsidian vault selection dialog. Obsidian does not expose a way to switch to another vault programmatically (yet?).
  • :ObsidianBridgeTelescopeCommand lists all the executable commands in Telescope. Execute the selected one.

๐Ÿ’ก Feel free to suggest additional useful commands via issue or PR.

๐Ÿ“œ Sync of buffer scrolling

Ideally scrolling within a note in neovim should also make the scroll position be centered in Obsidian. This is possible, but requires a patched version of Local REST API so we'll have to build it ourselves. For more info about the patch's status see this discussion.

Two ways of doing this, either build the fork or patch your local version

A) Build a forked version of obsidian-local-rest-api

Specifically what's required is a build based on this fork which hopefully can get integrated in the upstream project eventually.

Start off by cloning the patched fork to a folder named obsidian-local-rest-api-with-scroll:

git clone https://github.com/oflisback/obsidian-local-rest-api obsidian-local-rest-api-with-scroll

Then do npm install followed by npm run build inside that folder.

Now that you've built your own version of the plugin, place the obsidian-local-rest-api-with-scroll in your vault's .obsidian/plugins/ folder and enable the "Local REST API with Scroll" plugin in the Obsidian settings panel.

B) Patch your version of obsidian-local-rest-api

See this issue for a convenient script to accomplish this.

After either completing (A) or (B)

The final thing to do is to set scroll_sync = true in your obsidian-bridge.nvim configuration and update the OBSIDIAN_REST_API_KEY value to what was generated for the new version of the plugin.

Now scrolling a note in neovim should also result in scrolling in Obsidian. Note however that this only works if the note is in editing mode in Obsidian. Any suggestions on how to make it work also in view mode would be very appreciated, until then make sure that notes are opened in editing mode by default via the Obsidian setting Editor -> Default view for new tabs -> Editing view.

๐Ÿ“š Other projects for Neovim + Obsidian

  • obsidian.nvim Lets us interact with Obsidian vaults directly via the filesystem. ๐Ÿง 

๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Contributing

Contributions, bug reports and suggestions are very welcome.

If you have a suggestion that would make the project better, please fork the repo and create a pull request.

obsidian-bridge.nvim's People

Contributors

oflisback avatar cstsunfu avatar oonamo avatar

Stargazers

 avatar

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.