dotfiles/.config/nvim/lua/plugins/obsidian.lua

73 lines
2.5 KiB
Lua
Raw Normal View History

2024-01-21 16:23:44 +01:00
local function handle_enter()
2024-01-21 12:24:56 +01:00
local util = require("obsidian.util")
if util.cursor_on_markdown_link(nil, nil, true) then
vim.cmd("ObsidianFollowLink")
else
2024-01-21 16:23:44 +01:00
local line = vim.api.nvim_get_current_line()
2024-01-25 18:20:36 +01:00
if string.match(line, "^%s*- %[[x ]%].*") then
2024-01-21 16:23:44 +01:00
util.toggle_checkbox()
else
vim.cmd("normal! viw:'<,'>ObsidianLink")
end
2024-01-21 12:24:56 +01:00
end
end
return {
"epwalsh/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
2024-02-10 14:02:40 +01:00
lazy = false,
2024-01-21 12:24:56 +01:00
dependencies = { "nvim-lua/plenary.nvim" },
2024-03-11 14:09:12 +01:00
config = function(_, opts)
local notes_path = (os.getenv "HOME") .. "/Workspace/Notes"
2024-03-15 16:39:07 +01:00
if vim.fn.isdirectory(notes_path) == 0 then
return
end
2024-03-11 14:09:12 +01:00
local scan = require("plenary.scandir").scan_dir(notes_path, {add_dirs = true, depth = 1 })
local found = false
2024-03-11 14:09:12 +01:00
for _, v in ipairs(scan) do
local subdir = v:match("([^/]+)$")
found = true
2024-03-11 14:09:12 +01:00
if vim.fn.isdirectory(notes_path .. "/" .. subdir .. "/.obsidian") == 1 then
table.insert(opts.workspaces, {
name = subdir,
path = notes_path .. "/" .. subdir,
overrides = {
daily_notes = {
folder = "Daily",
},
2024-02-10 14:02:40 +01:00
},
2024-03-11 14:09:12 +01:00
})
end
end
if found then
require("obsidian").setup(opts)
end
2024-03-11 14:09:12 +01:00
end,
opts = {
workspaces = {},
2024-02-12 00:27:45 +01:00
note_id_func = function(title) return title end,
2024-03-11 14:09:12 +01:00
daily_notes = {
folder = "."
},
2024-01-24 21:45:15 +01:00
disable_frontmatter = true,
ui = {
hl_groups = {
ObsidianRefText = { fg = "#61afef" },
}
}
2024-01-21 12:24:56 +01:00
},
2024-03-11 14:09:12 +01:00
2024-01-21 12:24:56 +01:00
keys = {
2024-01-21 16:23:44 +01:00
{"<cr>", handle_enter, ft = "markdown" },
2024-02-10 14:02:40 +01:00
{"<cr>", "<cmd>ObsidianLink<cr>", ft = "markdown", mode = "v"},
{"<leader>rn", "<cmd>ObsidianRename<cr>", ft = "markdown" },
2024-02-08 15:16:48 +01:00
{"<leader>l", "i- [ ] ", ft = "markdown"},
2024-02-11 23:58:36 +01:00
{"<leader>o", "o- [ ] ", ft = "markdown"},
2024-02-08 15:16:48 +01:00
{"<leader>l", "- [ ] ", ft = "markdown", mode = "i" },
2024-02-10 14:26:58 +01:00
{"<leader>jt", "<cmd>ObsidianToday<cr>"},
{"<leader>jy", "<cmd>ObsidianYesterday<cr>"},
{"<leader>ju", "<cmd>ObsidianTomorrow<cr>"},
2024-01-21 16:23:44 +01:00
{"<tab>", ":set nohlsearch<cr>/\\[[^\\[\\]]*\\]([^()]*)<cr>:let @/ = \"\"<cr>:set hlsearch<cr>", ft = "markdown", silent = true },
2024-01-21 12:24:56 +01:00
},
}