neovimconfig/lua/plugin/obsidian.lua

122 lines
4 KiB
Lua

return {
{
"obsidian-nvim/obsidian.nvim",
version = "*", -- recommended, use latest release instead of latest commit
lazy = true,
ft = "markdown",
-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
-- event = {
-- -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
-- -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/*.md"
-- -- refer to `:h file-pattern` for more examples
-- "BufReadPre path/to/my-vault/*.md",
-- "BufNewFile path/to/my-vault/*.md",
-- },
dependencies = {
"nvim-lua/plenary.nvim",
},
opts = {
workspaces = {
{
name = "notes",
path = "~/notes",
},
},
completion = {
-- Set to false to disable completion.
nvim_cmp = true,
-- Trigger completion at 2 chars.
min_chars = 1,
},
mappings = {
-- Overrides the 'gf' mapping to work on markdown/wiki links within your vault.
["gf"] = {
action = function()
return require("obsidian").util.gf_passthrough()
end,
opts = { noremap = false, expr = true, buffer = true },
},
-- paste image
["<Space>Op"] = {
action = function()
return "<cmd>ObsidianPasteImg<cr>"
end,
opts = { noremap = false, expr = true, buffer = true },
},
["<Space>On"] = {
action = function()
return "<cmd>ObsidianNew<cr>"
end,
opts = { noremap = false, expr = true, buffer = true },
},
["<Space>Os"] = {
action = function()
return "<cmd>ObsidianSearch<cr>"
end,
opts = { noremap = false, expr = true, buffer = true },
},
-- Toggle check-boxes.
["<leader>ch"] = {
action = function()
return require("obsidian").util.toggle_checkbox()
end,
opts = { buffer = true },
},
["<cr>"] = {
action = function()
return require("obsidian").util.smart_action()
end,
opts = { buffer = true, expr = true },
},
["<Space>bl"] = {
action = function()
return "<cmd>ObsidianBacklinks<cr>"
end,
opts = { noremap = false, expr = true, buffer = true },
},
},
new_notes_location = "current_dir",
-- wiki_link_func = "use_alias_only",
wiki_link_func = function(opts)
return require("obsidian.util").wiki_link_id_prefix(opts)
end,
preferred_link_style = "wiki",
note_id_func = function(title)
return title
end,
-- note_id_func = function(title)
-- return tostring(os.date("%Y-%m-%d") .. "-" .. title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower())
-- end,
disable_frontmatter = true,
-- 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.
-- ---@param url string
-- follow_url_func = function(url)
-- -- Open the URL in the default web browser.
-- -- vim.fn.jobstart({ "xdg-open", url }) -- linux
-- vim.ui.open(url) -- need Neovim 0.10.0+
-- end,
--
-- -- Optional, by default when you use `:ObsidianFollowLink` on a link to an image
-- -- file it will be ignored but you can customize this behavior here.
-- ---@param img string
-- follow_img_func = function(img)
-- vim.fn.jobstart({ "xdg-open", img }) -- linux
-- end,
attachments = {
-- The default folder to place images in via `:ObsidianPasteImg`.
-- If this is a relative path it will be interpreted as relative to the vault root.
-- You can always override this per image by passing a full path to the command instead of just a filename.
img_folder = "images", -- This is the default
},
ui = { enable = false},
},
}
}