Something went wrong. Try again.
my neovim config
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476local obsidian = require("obsidian")
vim.api.nvim_set_hl(0, "ObsidianSyncSynced", { fg = "#18e379", bold = true })vim.api.nvim_set_hl(0, "ObsidianSyncSyncing", { fg = "#e5c07b" })vim.api.nvim_set_hl(0, "ObsidianSyncPaused", { fg = "#61afef" })
local buf = vim.api.nvim_get_current_buf()
vim.lsp.semantic_tokens.enable(true, { bufnr = buf })
require("obsidian-cite").setup({ source = { type = "better-bibtex-json", path = "~/My Library.json", },})
pcall(function() require("obsidian.lsp.watchfiles").register_handler(function(events, raw_changes) for _, event in ipairs(events) do if event.type == "renamed" then print("rename", event.old_path, "->", event.new_path) elseif event.type == "created" then print("created", event.path) elseif event.type == "deleted" then print("deleted", event.path) elseif event.type == "changed" then print("changed", event.path) end end end)end)
pcall(function() require("obsidian.media-db").setup({ apis = { omdb = { key = "debaf6f7" }, -- giant_bomb = { key = "0d3deb61eeed923a919def933ceeb4d168fa3f64" }, spotify = { id = os.getenv("SPOTIFY_CLIENT_ID"), secret = os.getenv("SPOTIFY_CLIENT_SECRET"), }, open_library = { enabled = false }, google_books = { key = "AIzaSyBiJEfKGhJ8PMrb2lSrFMSNgYUbvqZdBaM" }, }, media_types = { movie = { field_mappings = { director = { format = "[[%s]]" }, actors = { format = "[[%s]]" }, }, }, music = { field_mappings = { artists = { format = "[[%s]]" }, }, }, }, })
require("obsidian.spaced-repetition").setup({ auto_next_note = true, })end)
local handlers = { jisho = function(uri) local query = uri:gsub(vim.pesc("jisho://"), "") vim.cmd("Jisho " .. query) end, man = function(uri) local query = uri:gsub(vim.pesc("man://"), "") vim.cmd("Man " .. query) end, rfc = function(uri, overridden) local rfc_number = uri:gsub(vim.pesc("rfc://"), "") rfc_number = tonumber(rfc_number) local url = "https://www.rfc-editor.org/rfc/rfc" .. rfc_number .. ".txt" overridden(url, { cmd = { "zen-beta" } }) end,}
vim.ui.open = (function(overridden) return function(uri, opt) local ok, scheme = require("obsidian.util").is_uri(uri) if ok and handlers[scheme] then return handlers[scheme](uri, overridden) end if vim.endswith(uri, ".pdf") then opt = { cmd = { "zathura" } } -- override open app end if obsidian.api.get_os() == "Wsl" then opt = { cmd = { "wsl-open" } } else opt = { cmd = { "zen-beta" } } end return overridden(uri, opt) endend)(vim.ui.open)
vim.filetype.add({ extension = { base = "yaml", },})
local workspaces = { -- { -- name = "zettel", -- path = "~/Documents/Zettel/", -- }, { name = "notes", path = "~/Documents/Notes/", }, { name = "blog", path = "~/quarto-blog/posts/", }, -- { -- name = "config", -- path = "~/.config/nvim/", -- }, -- { -- name = "auto", -- path = function() -- local path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)) -- local prev = "" -- while path ~= "" and path ~= prev do -- if vim.uv.fs_stat(path .. "/.obsidian") then -- return path -- end -- prev, path = path, vim.fs.dirname(path) -- end -- return nil -- end, -- },}
require("obsidian.due_display")require("obsidian.yaml_vim_options")local _actions = require("obsidian._actions")local ut = require("obsidian._utils")
vim.keymap.set({ "i", "t" }, "<C-S-x>", ut.create_new_from_picker_prompt)vim.keymap.set("n", "<leader>dc", _actions.capture_to_daily)
local yazi_attachment_select = function() local tmp = vim.fn.tempname() local buf = vim.api.nvim_create_buf(false, true) local width = math.floor(vim.o.columns * 0.8) local height = math.floor(vim.o.lines * 0.8) local win = vim.api.nvim_open_win(buf, true, { relative = "editor", row = math.floor((vim.o.lines - height) / 2), col = math.floor((vim.o.columns - width) / 2), width = width, height = height, style = "minimal", border = "rounded", }) vim.fn.jobstart({ "yazi", "--chooser-file=" .. tmp }, { term = true, on_exit = function() vim.api.nvim_win_close(win, true) vim.api.nvim_buf_delete(buf, { force = true }) if vim.uv.fs_stat(tmp) then local lines = vim.fn.readfile(tmp) if lines[1] then require("obsidian.attachment").add(lines[1]) end end end, }) vim.cmd("startinsert")end
---@type table<string, obsidian.BacklinkMatch[]>local linked_mentions_cache = {}
---@param match obsidian.BacklinkMatch---@return string, integer, integer, stringlocal function backlink_sort_key(match) local rel_path = obsidian.Path.new(match.path):vault_relative_path() or tostring(match.path) return rel_path, match.line or 0, match.start or 0, match.text or ""end
---@param matches obsidian.BacklinkMatch[]---@return obsidian.BacklinkMatch[]local function sort_backlink_matches(matches) table.sort(matches, function(a, b) local a_path, a_line, a_start, a_text = backlink_sort_key(a) local b_path, b_line, b_start, b_text = backlink_sort_key(b)
if a_path ~= b_path then return a_path < b_path elseif a_line ~= b_line then return a_line < b_line elseif a_start ~= b_start then return a_start < b_start else return a_text < b_text end end)
return matchesend
obsidian.setup({ files = { trash = "local", }, bookmarks = { group = true, }, cache = { enabled = true, backend = "memory", ignore_patterns = { "^%.agents/", "^Archived/", }, },
sync = { -- backend = "git", -- backend = "rclone", trigger = "on_write", enabled = true, },
footer = { format = "{{status}}\n{{linked_mentions}}", substitutions = { linked_mentions = function(note, update) local path = tostring(note.path) if update or linked_mentions_cache[path] == nil then linked_mentions_cache[path] = sort_backlink_matches(note:backlinks({})) end local matches = linked_mentions_cache[path]
if #matches == 0 then return {} end
local lines = { "Linked Mentions", "" } for _, match in ipairs(matches) do local rel_path = obsidian.Path.new(match.path):vault_relative_path() or tostring(match.path) lines[#lines + 1] = string.format("%s: %s", rel_path, match.text or "") end
return lines end, }, },
completion = { min_chars = 2, },
backlinks = { parse_headers = true, },
callbacks = {
---@param note obsidian.Note enter_note = function(note) require("obsidian._paste")() -- override paste handler
local actions = require("obsidian.actions")
if vim.b[note.bufnr].obsidian_help then vim.bo[note.bufnr].readonly = false end
local function set(mode, lhs, rhs) vim.keymap.set(mode, lhs, rhs, { buffer = true }) end
vim.keymap.set("x", "<leader>ol", actions.link_new, { desc = "Link new" }) vim.keymap.set("x", "<leader>oL", actions.link, { desc = "Link" })
pcall(function() -- set("n", "<Tab>", actions.cycle_fold) -- set("n", "<S-Tab>", actions.cycle_folds_global) end)
pcall(function() vim.keymap.set("n", "<leader>A", actions.add_attachment, { buffer = true }) end)
pcall(function() vim.keymap.set("n", "<leader>W", actions.workspace_symbol, { buffer = true }) end)
pcall(function() vim.keymap.set("n", "<leader>ul", actions.unique_link, { buffer = true }) end)
pcall(function() vim.keymap.set("n", "<leader>xt", _actions.process_image, { buffer = true }) end)
-- vim.keymap.set("n", "<Tab>", actions.cycal_global_headings, { buffer = true })
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, { buffer = true }) vim.keymap.set("n", "<leader>p", function() if pcall(require, "obsidian.paste") then return "<cmd>Obsidian paste<cr>" else return "<cmd>Obsidian paste_img<cr>" end end, { buffer = true, expr = true })
pcall(function() vim.keymap.set("n", "<leader>;", obsidian.api.add_property, { buffer = true }) -- vim.keymap.set("n", "<leader>S", actions.start_presentation, { buffer = true }) end)
pcall(function() vim.keymap.set("n", "<leader>il", actions.insert_link, { buffer = true, }) vim.keymap.set("n", "<leader>it", actions.insert_tag, { buffer = true, }) vim.keymap.set("n", "<leader>ta", actions.tag_note, { buffer = true, }) end)
if vim.endswith(tostring(note.path), "todo.md") then vim.keymap.del("n", "<CR>", { buffer = true }) vim.keymap.set("n", "<CR>", "<cmd>Checkmate toggle<cr>", { buffer = true }) end
vim.keymap.set("n", "<leader>cb", obsidian.api.set_checkbox, { buffer = true, desc = "Obsidian set checkbox" })
vim.keymap.set( { "n", "x" }, "<leader>cc", obsidian.api.toggle_checkbox, { buffer = true, desc = "Obsidian toggle checkbox" } ) end, },
frontmatter = { enabled = false, func = function(note) local out = require("obsidian.builtin").frontmatter(note) if note.metadata and note.metadata.progress then local res = ut.count_checkbox(note) out.progress = string.format("%d/%d", res.done, res.total) end if vim.tbl_isempty(note.aliases) then out.aliases = nil end if vim.tbl_isempty(note.tags) then out.tags = nil end if #note.aliases == 1 and note.aliases[1] == note.id then out.aliases = nil end if note.id == note.path.stem then out.id = nil end return out end, -- enabled = function(path) -- if tostring(path):find("draft") then -- return false -- end -- if vim.endswith(tostring(path), ".qmd") then -- return false -- end -- -- if Obsidian.workspace.name == "wiki" then -- return false -- end -- -- return true -- end, },
-- lsp = { -- hover = { -- note_preview_callback = function(note) -- local contents = {} -- for i = 1, 20 do -- contents[i] = note.contents[i] -- end -- return contents -- end, -- }, -- },
legacy_commands = false,
link = { resolve = "strict", format = "shortest", -- format = "absolute", -- format = "relative", },
---@param id string ---@param dir obsidian.Path ---@return string note_id_func = function(id, dir) return id end,
comment = { enabled = false },
ui = { enable = false },
checkbox = { order = { " ", "x" }, create_new = true, },
open = { use_advanced_uri = false, schemes = { "zotero", "jisho", "man", "rfc", }, },
daily_notes = { enabled = true, template = "daily.md", folder = "Daily", default_tags = {}, workdays_only = false, },
picker = { -- enabled = false, -- name = "mini.pick", name = "snacks.pick", -- name = "fzf-lua", -- name = "telescope.nvim", },
attachments = { func = function(uri) vim.ui.open(uri) end, confirm_img_paste = true, folder = "./Attachments", -- resolve = yazi_attachment_select, },
templates = { folder = "Templates", date_format = "%Y-%m-%d", time_format = "%H:%M", },
unique_note = { folder = "Zettel", template = "unique.md", },
note = { template = "default.md", },
workspaces = workspaces,})