diff --git a/lua/astrocommunity/note-taking/obsidian-nvim/README.md b/lua/astrocommunity/note-taking/obsidian-nvim/README.md index 6c77f5a2f..249845e93 100644 --- a/lua/astrocommunity/note-taking/obsidian-nvim/README.md +++ b/lua/astrocommunity/note-taking/obsidian-nvim/README.md @@ -5,3 +5,16 @@ Neovim plugin for Obsidian, written in Lua **Repository:** A Neovim plugin for writing and navigating an [Obsidian](https://obsidian.md) vault, written in Lua. + +This config assumes the vault location is at `~/obsidian-vault`. You can move the vault there. If you instead want to change the location in the config, you can create a new file `plugins/obsidian.lua`, copy the contents of this `init.lua` to it, and then edit the 2 following lines + +`event = { "BufReadPre */obsidian-vault/*.md" },` + +and + +`dir = "~/obsidian-vault",` + +to match your vault location. + + +The plugin may also nag and ask you to create a `templates` directory in the vault. You can use `mkdir templates` to create an empty directory. diff --git a/lua/astrocommunity/note-taking/obsidian-nvim/init.lua b/lua/astrocommunity/note-taking/obsidian-nvim/init.lua index aa9a09cde..f60c052db 100644 --- a/lua/astrocommunity/note-taking/obsidian-nvim/init.lua +++ b/lua/astrocommunity/note-taking/obsidian-nvim/init.lua @@ -1,17 +1,54 @@ return { "epwalsh/obsidian.nvim", - cmd = { - "ObsdianBacklinks", - "ObsidianToday", - "ObsidianYesterday", - "ObsidianOpen", - "ObsidianNew", - "ObsidianSearch", - "ObsidianQuickSwitch", - "ObsidianLink", - "ObsidianLinkNew", - "ObsidianFollowLink", - "ObsidianTemplate", + -- the obsidian vault in this default config ~/obsidian-vault + -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand': + -- event = { "bufreadpre " .. vim.fn.expand "~" .. "/my-vault/**.md" }, + event = { "BufReadPre */obsidian-vault/*.md" }, + keys = { + { + "gf", + function() + if require("obsidian").util.cursor_on_markdown_link() then + return "ObsidianFollowLink" + else + return "gf" + end + end, + noremap = false, + expr = true, + }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + "hrsh7th/nvim-cmp", + "nvim-telescope/telescope.nvim", + }, + opts = { + dir = vim.env.HOME .. "/obsidian-vault", -- specify the vault location. no need to call 'vim.fn.expand' here + use_advanced_uri = true, + finder = "telescope.nvim", + + templates = { + subdir = "templates", + date_format = "%Y-%m-%d-%a", + time_format = "%H:%M", + }, + + note_frontmatter_func = function(note) + -- This is equivalent to the default frontmatter function. + local out = { id = note.id, aliases = note.aliases, tags = note.tags } + -- `note.metadata` contains any manually added fields in the frontmatter. + -- So here we just make sure those fields are kept in the frontmatter. + if note.metadata ~= nil and require("obsidian").util.table_length(note.metadata) > 0 then + for k, v in pairs(note.metadata) do + out[k] = v + end + end + return out + end, + + -- Optional, by default when you use `:ObsidianFollowLink` on a link to an external + -- URL it will be ignored but you can customize this behavior here. + follow_url_func = vim.ui.open or require("astronvim.utils").system_open, }, - opts = { completion = { nvim_cmp = true } }, }