Git Product home page Git Product logo

obs.nvim's Introduction

obs.nvim

Simple NeoVim plugin with Obsidian-like-notes support.

Why is it better than Obsidian:

  • Making notes inside NeoVim during coding sessions.
  • Lua as extension language.
  • Existing NeoVim infrastructure.

Status

Project is currently in WIP status.

Installation

This project requires:

Plugin provides a source for completion using hrsh7th/nvim-cmp: A completion plugin for neovim coded in Lua..

Example installation using folke/lazy.nvim:

return {
    {
        "IlyasYOY/obs.nvim",
        dependencies = {
            "IlyasYOY/coredor.nvim",
            "nvim-lua/plenary.nvim",
            "nvim-telescope/telescope.nvim",
        },
        dev = true,
        config = function()
            local obs = require "obs"

            obs.setup {
                vault_home = "~/Notes",
                vault_name = "Notes",
                journal = {
                    template_name = "daily",
                },
            }

            vim.keymap.set("n", "<leader>nn", "<cmd>ObsNvimFollowLink<cr>")
            vim.keymap.set("n", "<leader>nr", "<cmd>ObsNvimRandomNote<cr>")
            vim.keymap.set("n", "<leader>nN", "<cmd>ObsNvimNewNote<cr>")
            vim.keymap.set("n", "<leader>ny", "<cmd>ObsNvimCopyObsidianLinkToNote<cr>")
            vim.keymap.set("n", "<leader>no", "<cmd>ObsNvimOpenInObsidian<cr>")
            vim.keymap.set("n", "<leader>nd", "<cmd>ObsNvimDailyNote<cr>")
            vim.keymap.set("n", "<leader>nw", "<cmd>ObsNvimWeeklyNote<cr>")
            vim.keymap.set("n", "<leader>nrn", "<cmd>ObsNvimRename<cr>")
            vim.keymap.set("n", "<leader>nT", "<cmd>ObsNvimTemplate<cr>")
            vim.keymap.set("n", "<leader>nM", "<cmd>ObsNvimMove<cr>")
            vim.keymap.set("n", "<leader>nb", "<cmd>ObsNvimBacklinks<cr>")
            vim.keymap.set("n", "<leader>nfj", "<cmd>ObsNvimFindInJournal<cr>")
            vim.keymap.set("n", "<leader>nff", "<cmd>ObsNvimFindNote<cr>")
            vim.keymap.set("n", "<leader>nfg", "<cmd>ObsNvimFindInNotes<cr>")
        end,
    },
}

Configuration

My configuration you can find here.

setup

Example setup:

obs.setup {
    journal = {
        -- setting for daily template note name
        template_name = "daily",
    },
}

Type definition for table is provided here as obs.VaultOpts.

I won't go over all configuration options in details. There are the most important defaults the plugin provides:

  • ~/vimwiki as directory for notes, with sub-directories:
    • ./meta/templates as templates folder.
    • ./diary as daily notes folder.

mappings

Example mappings configuration may be found here.

  • Insert template using telescope. :ObsNvimTemplate opens dialog with <CR> mapped to insert template in the line below.
  • Follow link under cursor. :ObsNvimFollowLink.
  • Open random note. :ObsNvimRandomNote.
  • Copy obsidian link to a current note. :ObsNvimCopyObsidianLinkToNote.
  • Open obsidian link to a current note. :ObsNvimOpenInObsidian. If you don't have Browse command then you can create it manually like so.
  • Creates a new note. :ObsNvimNewNote prefixes note with YYYY-MM-dd. In case of empty name plugin generates name from time-stamp. Example: 2023-03-12 1678625141.md.
  • Opens daily note. :ObsNvimDailyNote creates one if doesn't exist.
  • Opens weekly note. :ObsNvimWeeklyNote creates one if doesn't exist.
  • Telescope find notes. :ObsNvimFindNote.
  • Telescope find journal notes. :ObsNvimFindInJournal.
  • Telescope live-grep through notes. :ObsNvimFinInNotes.
  • Telescope through back-links. :ObsNvimBacklinks.
  • Renames current note. :ObsNvimRename updates links to the note. I advice you to rename notes inside Obsidian for important notes with lots of back-links.
  • Move note to directory from search. :ObsNvimMove launches telescope to find directory to move current note to.
  • Setup nvim-cmp completion source. After that you'll be able to use completion for notes inside your vault.
-- config for nvim-cmp
local cmp_source = require "obs.cmp-source"
cmp.register_source("obs", cmp_source.new())

-- config for obs.nvim
local group = vim.api.nvim_create_augroup(
    "ObsNvim",
    { clear = true }
)

vim.api.nvim_create_autocmd({ "BufEnter" }, {
    group = group,
    pattern = "*.md",
    desc = "Setup notes nvim-cmp source",
    callback = function()
        if obs.vault:is_current_buffer_in_vault() then
            require("cmp").setup.buffer {
                sources = {
                    { name = "obs" },
                    { name = "luasnip" },
                },
            }
        end
    end,
})

Tips

  • Here you can find useful LuaSnip snippets for Obsidian.

obs.nvim's People

Contributors

ilyasyoy 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

Watchers

 avatar

Forkers

kustikk

obs.nvim's Issues

Move note to directory dialog

Is your feature request related to a problem? Please describe.

As a heavy Obsdiain user I like their Move current file to another folder command. I'd like to have a similar dialog.

Describe the solution you'd like

I see possible solution might be implemented using telescope search through directories and custom selection handler.

Describe alternatives you've considered

I move files manually using neo-tree. Usually I use Obsidian to handle file management.

Additional context

Search through todo items

Is your feature request related to a problem? Please describe.

As a user I want tot have a way to search through all todos in the vault.

Describe the solution you'd like

We might be able to populate telescope search with items from files in the vault.

Describe alternatives you've considered

There are no viable alternative to do this outside of Obsidian.

Additional context

todo/list interactions

Is your feature request related to a problem? Please describe.

Obsidian allow me to interact with TODO-list item using commands:

  • toggle bullet list,
  • toggle checkbox status.

That'd be cool to have a similar feature here.

Describe the solution you'd like

The Vault abstraction might provide a method which will cycle through different list options:

  • bullet,
  • checkbox,
  • no list.

Describe alternatives you've considered

Doing it manually is fine, but not very convenient. I use lua-snip to ease the pain.

Additional context

Issue & PR template

I have to create templates for PRs and issues.

Issue templates:

  • question,
  • bug,
  • feature.

PR templates:

  • one template to rule them all.

relative path vault_home in setup

My setup function

require("obs").setup({
	vault_home = "~/Obsidian",
})

I add insert template keymap and when I try to insert template nvim says "Current buffer is not a note"

vim.keymap.set("n", "<leader>nT", function()
	obs.vault:run_if_note(function()
		obs.vault:find_and_insert_template()
	end)
end, { desc = "Inserts notes Template" })

if I change my config to absolute path it works fine

local Path = require("plenary.path")
require("obs").setup({
	vault_home = (Path:new(Path.path.home) / "Obsidian"):absolute(),
})

it also works fine if change is_current_buffer_in_vault

from:
---checks if this buffer in the vault, usefull in autocommands.
---@return boolean
function Vault:is_current_buffer_in_vault()
    local file_name = vim.api.nvim_buf_get_name(0)
    return core.string_has_prefix(file_name, self._home_path:absolute(), true)
end
to:
---checks if this buffer in the vault, usefull in autocommands.
---@return boolean
function Vault:is_current_buffer_in_vault()
    local file_name = vim.api.nvim_buf_get_name(0)
    return core.string_has_prefix(file_name, self._home_path:expand(), true)
end

Copy current note link

Is your feature request related to a problem? Please describe.

I want to easily copy a link to a note i'm working on. This allows me to easily reference it.

Describe the solution you'd like

Copy [[current note name]] using y command.

Describe alternatives you've considered

There are no alternatives.

Additional context

Weekly notes

Is your feature request related to a problem? Please describe.

Obsidian supports weekly notes. The support is provided via third-party plugin: https://github.com/liamcain/obsidian-calendar-plugin.

Describe the solution you'd like

I'd like to have API similar to existing of daily notes. API might be a part of Journal abstraction.

Describe alternatives you've considered

Using telescope to search already created weekly notes is fine. But it's read-only way to interact with them.

Additional context

Calendar ๐Ÿ“… View

Is your feature request related to a problem? Please describe.

As a user I want something similar to Obsidian Calendar Plugin.

Describe the solution you'd like

I want to be able to have calendar-like buffer where I can choose arbitrary date and navigate to corresponding daily note (or create one of the note doesn't exist yet).

Describe alternatives you've considered

Searching dates manually.

Additional context

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.