Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(obsidian-nvim): added obsidian.nvim config and changed the readme #378

Merged
merged 9 commits into from
Jul 9, 2023
13 changes: 13 additions & 0 deletions lua/astrocommunity/note-taking/obsidian-nvim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ Neovim plugin for Obsidian, written in Lua
**Repository:** <https://github.com/epwalsh/obsidian.nvim>

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.
63 changes: 50 additions & 13 deletions lua/astrocommunity/note-taking/obsidian-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -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 "<cmd>ObsidianFollowLink<CR>"
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 } },
}