dotfiles/nvim/lua/plugins/obsidian.lua

79 lines
2.6 KiB
Lua

local function handle_enter()
local util = require("obsidian.util")
if util.cursor_on_markdown_link(nil, nil, true) then
vim.cmd("ObsidianFollowLink")
else
local line = vim.api.nvim_get_current_line()
if string.match(line, "^%s*- %[[x ]%].*") then
util.toggle_checkbox()
else
vim.cmd("normal! viw:'<,'>ObsidianLink")
end
end
end
return {
"epwalsh/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
lazy = false,
dependencies = { "nvim-lua/plenary.nvim" },
opts = {
workspaces = {
{
name = "Lumentis",
path = "~/Workspace/DnD/Lumentis",
},
{
name = "Notes",
path = "~/Workspace/Notes",
},
{
name = "PhD-Notes",
path = "~/Workspace/University/PhD/Notes",
},
{
name = "DnD",
path = "~/Workspace/DnD",
},
{
name = "no-vault",
path = function()
-- alternatively use the CWD:
return assert(vim.fn.getcwd())
-- return assert(vim.fs.dirname(vim.api.nvim_buf_get_name(0)))
end,
overrides = {
notes_subdir = vim.NIL, -- have to use 'vim.NIL' instead of 'nil'
completion = {
new_notes_location = "current_dir",
},
},
},
},
daily_notes = {
folder = "Daily",
},
disable_frontmatter = true,
ui = {
hl_groups = {
ObsidianRefText = { fg = "#61afef" },
}
}
},
keys = {
{"<cr>", handle_enter, ft = "markdown" },
{"<cr>", "<cmd>ObsidianLink<cr>", ft = "markdown", mode = "v"},
{"<leader>rn", "<cmd>ObsidianRename<cr>", ft = "markdown" },
{"<leader>l", "i- [ ] ", ft = "markdown"},
{"<leader>o", "o- [ ] ", ft = "markdown"},
{"<leader>l", "- [ ] ", ft = "markdown", mode = "i" },
{"<leader>jt", "<cmd>ObsidianToday<cr>"},
{"<leader>jy", "<cmd>ObsidianYesterday<cr>"},
{"<leader>ju", "<cmd>ObsidianTomorrow<cr>"},
{"<tab>", ":set nohlsearch<cr>/\\[[^\\[\\]]*\\]([^()]*)<cr>:let @/ = \"\"<cr>:set hlsearch<cr>", ft = "markdown", silent = true },
},
config = function (_, opts)
require("obsidian").setup(opts)
end
}