Skip to content

Commit

Permalink
fix(obsidian-nvim): added obsidian.nvim config and changed the readme (
Browse files Browse the repository at this point in the history
…#378)

* added obsidian.nvim config and changed the readme

* added vim.env.HOME to the config

* fix(obsidian-nvim): os agnostic link opening

* fix(obsidian-nvim): proper key nesting

* refactor(obsidian-nvim): return to opts table from function

* fix(obsidian-nvim): remove default values

the removed opts are already set to the same values by default, see here: https://github.com/epwalsh/obsidian.nvim/blob/main/lua/obsidian/config.lua

* feat(obsidian-nvim): add Windows support for URLs

Co-authored-by: Uzair Aftab <[email protected]>

* fix(obsidian-nvim): remove empty line

* fix(obsidian-nvim): Use astronvim utils or native vim api's to open file

Co-authored-by: Micah Halter <[email protected]>

---------

Co-authored-by: mortang2410 <[email protected]>
Co-authored-by: Olivier Wittek <[email protected]>
Co-authored-by: Uzair Aftab <[email protected]>
Co-authored-by: Micah Halter <[email protected]>
  • Loading branch information
5 people authored Jul 9, 2023
1 parent 74393f5 commit 3234929
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
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 } },
}

0 comments on commit 3234929

Please sign in to comment.