This post is part of a cookbook of tricks for Obsidian, the markdown note taking app. If you are new to Obsidian start here.
When inserting notes in Obsidian I often want to both build a web of links between articles as well as maintain a Map of Content. Because I do this a lot, it can start to feel like a bit like a stream of continuous paper cuts if . The completion on link insertion with [[ helps. But another thing that can be useful is inserting links based upon your history.
For these snippets you first need to install the Pane Relief plugin.
This snippet in Plugin REPL helps by either inserting a link to the previous note in your history.
newCommand(function link_history() {
let stack = view.leaf["pane-relief:history-v1"].stack
let pos = view.leaf["pane-relief:history-v1"].pos
insert("[[" + stack[pos + 1].path.replace(/\..*/, "") + "]]")
})
If you have installed plugin REPL you can paste it anywhere and then execute it with Plugin REPL: Execute the current line or selection . Then if you like it you can add it to plugin REPL’s repl.md startup file.
Looking at the last few files
Sometime sit can be useful to insert a link to the file in the recent history. You can use a snippet for this.
newCommand(async function link_history_select() {
let stack = view.leaf["pane-relief:history-v1"].stack
let pos = view.leaf["pane-relief:history-v1"].pos
let path = await fuzzySelect(stack.slice(pos +1, pos + 10).map((x) => x.path))
insert("[[" + path.replace(/\..*/, "") + "]]")
})
Shortcuts
After executing this code you can run this from the command palette or create a shortcut. I use Ctrl-Alt-L and Ctrl-Alt-Shift-L.
You don’t need to use Plugin REPL
I wrote Plugin REPL and find it useful. However, you could adapt these scripts for Templater or Dataview.
Finishing up
I hope you found this interesting. If you did you might like to read about
I am readwithai. I make tools related to reading and agency sometimes to do with Obsidian and write about this. I am the author of Plugin REPL
If this sounds interesting you can follow me on X or read my blog.