obsidian.nvim
obsidian.nvim copied to clipboard
WARNING: The file has been changed since reading it!!!
🐛 Describe the bug
Description
After using ObsidianNew
, ObsidianRename
or ObsidianExtractNode
and saving, I get this invasive warning, I already tried to leave the note_frontmatter_func
by default and it doesn't work either.
Preview
Disclaimer
I don't know if this is a bug in obsidian.nvim
or if it is some kind of vim.opt
Config
return {
'epwalsh/obsidian.nvim',
version = '*',
ft = 'markdown',
enabled = true,
keys = {
{ '<leader>ob', '<cmd>ObsidianBacklinks<cr>', desc = '[O]bisidan [B]acklinks' },
{ '<leader>od', '<cmd>ObsidianDailies<cr>', '[O]sidian [D]ailies' },
{
'<leader>oe',
function()
vim.ui.input({ prompt = 'Enter Note Title: ' }, function(title)
if title == nil or title == '' then
return
end
vim.cmd('ObsidianExtractNote ' .. title)
end)
end,
desc = '[O]sidian [E]xtract Note',
mode = { 'v' },
},
{ '<leader>ol', '<cmd>ObsidianLinks<cr>', '[O]sidian [L]inks' },
{ '<leader>on', '<cmd>ObsidianNew<cr>', '[O]sidian [N]ew' },
{ '<leader>oo', '<cmd>ObsidianOpen<cr>', desc = '[O]pen in [O]bsidian' },
{ '<leader>oq', '<cmd>ObsidianQuickSwitch<cr>', '[O]sidian [Q]uick Swith' },
{ '<leader>or', '<cmd>ObsidianRename<cr>', '[O]sidian [R]ename' },
{ '<leader>os', '<cmd>ObsidianSearch<cr>', '[O]sidian [S]earch' },
{ '<leader>ot', '<cmd>ObsidianTags<cr>', '[O]sidian [T]ags' },
},
config = function()
---@diagnostic disable: missing-fields
require('obsidian').setup({
workspaces = {
{
name = 'second-brain.md',
path = '~/Documents/second-brain.md',
},
},
completion = {
min_chars = 2,
},
attachments = {
img_folder = '900-assets',
},
mappings = {
['<leader>ch'] = {
action = function()
return require('obsidian').util.toggle_checkbox()
end,
opts = { buffer = true, desc = 'Toggle [C][H]eck boxes' },
},
},
ui = {
bullets = { char = '•', hl_group = 'ObsidianBullet' },
checkboxes = {},
enable = true,
external_link_icon = { char = '', hl_group = 'ObsidianExtLinkIcon' },
highlight_text = { hl_group = 'ObsidianHighlightText' },
reference_text = { hl_group = 'ObsidianRefText' },
tags = { hl_group = 'ObsidianTag' },
update_debounce = 284,
hl_groups = {
ObsidianBullet = { bold = true, fg = '#89ddff' },
ObsidianDone = { bold = true, fg = '#89ddff' },
ObsidianExtLinkIcon = { fg = '#c792ea' },
ObsidianHighlightText = { bg = '#75662e' },
ObsidianRefText = { underline = true, fg = '#c792ea' },
ObsidianRightArrow = { bold = true, fg = '#f78c6c' },
ObsidianTag = { italic = true, fg = '#89ddff' },
ObsidianTilde = { bold = true, fg = '#ff5370' },
ObsidianTodo = { bold = true, fg = '#f78c6c' },
},
},
wiki_link_func = 'prepend_note_path',
note_frontmatter_func = function(note)
if note.title then
note:add_alias(note.title)
end
local current_date = os.date('%Y-%m-%d, %I:%M %p')
local out = {
aliases = note.aliases,
created_at = current_date,
id = note.id,
tags = note.tags,
updated_at = current_date,
}
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
out.updated_at = current_date
---@diagnostic disable-next-line: redundant-return-value
return out
end,
new_notes_location = 'current_dir',
note_id_func = function(title)
local suffix = ''
if title ~= nil then
-- If title is given, transform it into valid file name.
suffix = title:gsub(' ', '-'):gsub('[^A-Za-z0-9-]', ''):lower()
else
-- If title is nil, just add 4 random uppercase letters to the suffix.
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return tostring(os.date('%Y%m%d%H%M%S')) .. '-' .. suffix
end,
daily_notes = {
folder = '000-calendar/00-dailies',
date_format = '%Y-%m-%d',
alias_format = '%A, %d %B %Y',
template = nil,
},
follow_url_func = function(url)
vim.fn.jobstart({ 'brave', url })
end,
})
end,
}
Environment
nvim --headless -c 'lua require("obsidian").info()' -c q
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
Obsidian.nvim v3.7.6 (d70f3289399c25153b7f503b838afbf981124a37)
Status:
• buffer directory: nil
• working directory: /home/nikola/Documents/second-brain.md
Workspaces:
✓ active workspace: Workspace(name='second-brain.md', path='/home/nikola/Documents/second-brain.md', root='/home/nikola/Documents/second-brain.md')
Dependencies:
✓ plenary.nvim: 8aad4396840be7fc42896e3011751b7609ca4119
✓ nvim-cmp: ce16de5665c766f39c271705b17fff06f7bcb84f
Integrations:
✓ picker: TelescopePicker()
✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
all sources:
• copilot
• nvim_lsp
• nvim_lua
• luasnip
• emmet
• nvim_lsp_signature_help
• buffer
• path
• calc
• rg
Tools:
✓ rg: ripgrep 14.1.0
Environment:
• operating system: Linux
Config:
• notes_subdir: nil%
I actually get the same problem just saving :w
the note.
I think (in my case) it might be related to the updated
field changing:
Edit: autoread
is enabled in my config, but it often does not work the best. Seems this is something upstream Neovim might work on in the future (https://github.com/neovim/neovim/issues/1380). The fact that the files are stored on the windows side of WSL, might not help either
I'm having the same problem, strangely enough some projects have it and some don't!
The problem was having nvim
& obsidian
open at the same time, I suppose due to plugins that I have in obsidian and plugins that I have in nvim
that do actions when I save, such as lint, formatting etc...
Btw, I still have my functions for updated_at
and it is not the problem in case anyone considers it
Should I close the issue?
I'm also having this issue. Unrelated to having obsidian open in my case.
One thing I've found is that I get some weird error message when I preemptively run :e!
in a file.
It seems once I open at least one file and go through this dance, subsequent files seem fine.