Closed dim-anis closed 9 months ago
I have a similar problem. the command ObsidianNew
creates a note in whatever cwd
I'm in.
This looks like a duplicate of https://github.com/epwalsh/obsidian.nvim/issues/395. To get the desired behavior just set completion.new_notes_location = "notes_subdir"
in your obsidian.nvim config.
This has come up a few times recently so I think I'll change the default in the README to that.
FYI I moved that option to the top-level in f753d0d. This should make it more obvious.
@epwalsh the thing is I have set that option.
To make my problem clearer when I'm in my daily
folder within the vault if I create a link to a file that doesn't exist yet and trigger completion it is still created in the current folder, even with the new_notes_location
set to notes_subdir
.
The notes_subdir
is located one level above the daily
dir where .obsidian
is.
@dim-anis I'm not able to reproduce. Can you paste your config?
Sure, @epwalsh, here it is:
return {
"epwalsh/obsidian.nvim",
version = "*",
lazy = true,
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
},
init = function()
require("which-key").register({ o = { name = "+obsidian" } }, { prefix = "<leader>", mode = { "n", "v" } })
end,
keys = {
{ "<leader>on", "<cmd>ObsidianNew<CR>", desc = "New Note" },
{ "<leader>od", "<cmd>ObsidianToday<CR>", desc = "Todays Note" },
},
opts = {
dir = "~/Documents/obsidian",
notes_subdir = "notes",
completetion = {
nvim_cpm = true,
min_chars = 2,
new_notes_location = "notes_subdir",
preferred_link_style = "markdown",
},
mappings = {
-- Open obsidian link.
["fo"] = {
action = function()
return require("obsidian").util.gf_passthrough()
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 },
},
},
prepend_note_id = true,
-- Optional, customize how names/IDs for new notes are created.
note_id_func = function(title)
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
-- In this case a note with the title 'My new note' will be given an ID that looks
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
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
return tostring(os.time()) .. "-" .. suffix
end,
log_level = vim.log.levels.INFO,
daily_notes = {
folder = "/daily",
-- Optional, if you want to change the date format for the ID of daily notes.
date_format = "%Y-%m-%d",
-- Optional, if you want to change the date format of the default alias of daily notes.
alias_format = "%B %-d, %Y",
-- Optional, if you want to automatically insert a template from your template directory like 'daily.md'
-- template = "templates/daily.md",
},
templates = {
subdir = "templates",
date_format = "%Y-%m-%d",
time_format = "%H:%M",
-- A map for custom variables, the key should be the variable and the value a function
substitutions = {},
},
-- 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.
follow_url_func = function(url)
-- Open the URL in the default web browser.
vim.fn.jobstart({ "open", url }) -- Mac OS
-- vim.fn.jobstart({"xdg-open", url}) -- linux
end,
-- Optional, set to true if you use the Obsidian Advanced URI plugin.
-- https://github.com/Vinzent03/obsidian-advanced-uri
use_advanced_uri = false,
picker = {
-- Set your preferred picker. Can be one of 'telescope.nvim', 'fzf-lua', or 'mini.pick'.
name = "telescope.nvim",
-- Optional, configure key mappings for the picker. These are the defaults.
-- Not all pickers support all mappings.
mappings = {
-- Create a new note from your query.
new = "<C-x>",
-- Insert a link to the selected note.
insert_link = "<C-l>",
},
},
-- Specify how to handle attachments.
attachments = {
img_folder = "assets/imgs",
},
},
}
Huh, still not able to repro. Can you make sure you're on the latest commit and send me the output of :ObsidianDebug
?
Sure, @epwalsh
Status:
Buffer directory: '/Users/dimanis/Documents/obsidian/daily'
Working directory: '/Users/dimanis/Documents/obsidian'
Workspaces:
Active workspace: Workspace(name='obsidian', path='/Users/dimanis/Documents/obsidian', root='/Users/dimanis/Documents/obsidian')
Config:
notes_subdir: 'notes'
@epwalsh and here is a gif of the workflow, just to make sure we're on the same page:
Thanks @dim-anis. Uhhh I don't see how this could happen and I've set up a vault in the same way, but it works as expected for me 🤔
If you get a chance please try to debug on your own. The relevant function is Client:new_note()
. You can call this programmatically like this:
:lua require("obsidian").get_client():new_note("new note", "123-new-note")
Maybe just throw some print statements into Client:new_note()
to see what it resolves the path
to.
Sure, I'll take a look at it when I have time.
Thanks for this great plugin, @epwalsh!
@epwalsh I did some debugging and found out that it was due to the type in the config, specifically this part:
completetion = {
nvim_cpm = true,
min_chars = 2,
new_notes_location = "notes_subdir",
preferred_link_style = "markdown",
},
So "completetion" instead of completion
. new_notes_location
was using the default current_dir
value as a result.
Oh, well.
🐛 Describe the bug
When I create a link from within a daily note inside of a "daily-notes" folder the new note gets added to the current folder ("daily-notes") and not the notes_subdir.
I have configured the plugin exactly as in the readme. Interestingly, the notes folder gets created if it isn't present, but the new note is still placed in the current folder.
Versions
NVIM v0.9.5 Build type: Release LuaJIT 2.1.1703358377
[obsidian.nvim (v3.2.0)] Commit SHA: 0a6739d2229c8eb30396db550f3818e092088c27 [plenary.nvim] Commit SHA: 4f71c0c4a196ceb656c824a70792f3df3ce6bb6d [nvim-cmp] Commit SHA: 04e0ca376d6abdbfc8b52180f8ea236cbfddf782 ripgrep 14.1.0