epwalsh / epwalsh/obsidian.nvim
Enable users to create custom commands opening new notes with templates
- Dominant language
- Lua
- Stars
- 6.2k
- Forks
- 250
- PR merge metrics
- No merged PRs in 30d
Description
### 🚀 The feature, motivation and pitch
I wanted to create a note template which acts as my journaling template, since the command available for a daily note is ObsidianToday, which is the only command that creates a note with todays date as title, i was wondering if it is possible to create commands like lets call it "OpenNewJournalEntry", that offers the same feature as ObsidianToday, but enables adding of custom tags, and a custom template
### Alternatives
I was able to create a command in lua as keymap, but it doesnt work with obsidian.nvim together (especially opening the note like ObsidianNew or ObsidianToday does, in the obsidian vault working directory), this is the function i came up with, but i would love a connection with obsidian.nvim, to open it up in the correct folder after creating it.
```lua
vim.api.nvim_create_user_command("OpenDailyNote", function()
local date_format = "%Y-%m-%d"
local obsidian_vault_dir = "~/Documents/second-brain/"
local daily_folder = obsidian_vault_dir .. "NOTES/JOURNAL"
local template_path = obsidian_vault_dir .. "Templates/JournalTemplate.md"
local date = os.date(date_format)
local note_path = vim.fn.expand(daily_folder .. "/" .. date .. ".md")
local id = tostring(os.time())
if vim.fn.filereadable(note_path) == 0 then
vim.fn.mkdir(vim.fn.expand(daily_folder), "p")
local front_matter = table.concat({
"---",
"id: " .. id,
"title: " .. date,
"tags: [journaling]",
"---",
"",
}, "\n")
local file = io.open(note_path, "w")
file:write(front_matter)
if template_path and #template_path > 0 then
local template = io.open(template_path, "r")
if template then
local content = template:read("*all")
file:write(content)
template:close()
end
end
file:close()
end
end, {}),
```
### Additional context
_No response_
Contributor guide
Research direction
Start by reading the existing ObsidianToday and ObsidianNew command implementations mentioned in the issue, then trace how they select the vault working directory, templates, tags, and note paths. Done should mean users can define a custom command that creates a new templated note with custom metadata and opens it in the correct vault location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, neovim
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100