URL Scheme: direct navigation to heading

I apologize for trying to offer my help…

Yeah, I read the title - but after reading your second post, including your question what “relative links” mean, I wasn’t quite sure if the meaning of URL scheme was clear or if, instead, you were just trying to establish internal links between your notes…

This would be super useful. And also having the ability to right click on a heading in a note and to copy the obsidian URL directly to that heading.

Usecase: setting up ‘deep links’ between my various vaults

6 Likes

For URL Scheme: I’m curious what would happen with #headingtitle conflicts i.e. if one note has 2 identical #headingtitles.

(Ideally we should probably avoid using identical #headingtitles but mistakes happen.) Maybe the URL scheme can default to navigating to the first #headingtitle but highlighting both just so we can see that there are multiple.

Optionally: maybe the user could choose to create a URL for block as opposed to the #headingtitle. Advantage: no name conflict. Disadvantage: URL is less readable, just a long number.

1 Like

Q: re: linking to specific section in notes

Is there a way to create a link to a specific place in a markdown document in obsidian? eg Obsidian has ‘copy obsidian url’ for a specific note, but what if i want a url to go to a specific header?

We already have:
obsidian://open?vault=Notes&file=xxzz.md

Can we get something like this?
obsidian://open?vault=Notes&file=xxzz.md#myheader

Use case:

I want to add a link to the specific note and location (sub header) to my task manager.

When I come back to the task in my task manager, I want to click the link which will open the file in obsidian, but I want it to go to the specific header, which will provide the context in which I captured the task.

4 Likes

Does anyone know when feature requests get reviewed/evaluated and prioritized?

Checking back in on this.

Is there a feature review cycle for requests like this?

1 Like

I’m also interested in this, I thought this would work already…


Another use case:

I have my task lists inside Obsidian as list items, and some of the tasks have due dates.
I’m working on syncing these to my Google Calendar.

Once I get the calendar syncing to work, it would be nice to have a link in the calendar event, which would take me straight to the task item, using a block reference.

So, the URI in the calendar event would look something like (possibly with URI encoding for # and ^):
obsidian://open?vault=VaultName&file=FileName#^block-reference-id

Or with the shorthand URIs (which are much nicer):
obsidian://vault/VaultName/FileName#^block-reference-id

Vice versa, the task item in Obsidian would have a URL to the synced event in Google Calendar.


EDIT:
I’ll probably use a search URI at first, but it’s not nearly as nice:
obsidian://search?vault=VaultName&query=^block-reference-id

3 Likes

I like the idea of a search UI. How has this been working for you? Sufficient or still lacking a particular functionality? Additional friction (extra clicks / context switching / etc)?

It’s been working okay, it’s basically one extra click, since you need to click the top search result, instead of the file opening automatically in Obsidian.

Also, Google Calendar only supports web URLs (http:// and https://), so I had to write a small “proxy” web app. Google Calendar opens the “proxy” app, and it opens the obsidian:// URI using JavaScript. This also causes an extra click, because the browser (Chrome) doesn’t allow the “proxy” tab to close itself automatically (might be possible with a browser extension, but too much effort for the minor gain).

So, it’s 3 clicks: link, search result, close tab. It could be one click less, if Obsidian supported direct navigation to headings / block references.

2 Likes

I’d also love to see this.

My use case:
I use the Obsidian_To_Anki plugin for uni notes. The created cards automatically contain a link to the notes in which they were defined, but I have an extra note (per lecture) just for the anki cards. Optimally, I’d like to be able to directly link to the topic (header) in the real note to quickly read up on something I don’t get right aways by just looking at the card.

Right now, Obsidian opens, but with the message

File “Note#Header” not found.

1 Like

I didn’t read the whole discussion, but I think the Advanced-URI plugin should help you. It supports navigating (and writing) to specific headings via the heading parameter.

3 Likes

The Advanced-URI plugin does indeed work, but it would stil be nice if the native obsidian:// URL Scheme supported either of

  • obsidian://open?vault=Foo&file=Bar#Baz
  • obsidian://open?vault=Foo&file=Bar&header=Baz
2 Likes

Using a multi-vault (A-Z) system now on mobile and the URL scheme to jump from vault to vault and indeed the ability to jump to headings would be nice.

Not pleasant to type or look at, but these seem to work (Advanced URI is off):

### Link to heading → %23%23%23Training = ###Training
obsidian://open?vault={VAULT}&file={MY%20NOTE}%23%23%23{Training}

Link to heading → %23Training = #nTraining

obsidian://open?vault={VAULT}&file={MY%20NOTE}%23{Training}
(Thanks @berot3; see next post…)

Link to block → %23%5ECardio = #^Cardio

obsidian://open?vault={VAULT}&file={MY%20NOTE}%23%5E{Cardio}

2 Likes

that does it! Just a note, one %23 (#) is enough for headings. I guess its the same rule es for normal heading-linking (you write only [[#heading]] no matter if it is H3 etc)

2 Likes

Ah! good catch! I was just thinking # = %23, so why not three of 'em. :laughing:

I actually noticed this a bit ago when trying to link to a ### References, but there was another ## References above it in the same note that I had forgotten about. Unique headings, no matter the level, for the win!

1 Like

Yet another update. I saw this post, and hoped that using an Obsidian URI for linking to a specific sub-heading (if there were multiple of the same name) would work. Sure does!

The link:
[[Untitled 1#Biggest header 2#smol header]]

The URI:
obsidian://open?vault={VAULT}&file=Untitled%201%23Biggest%20header%202%23smol%20header%20)

The markdown:

# Biggest header

### smol header

# Biggest header 2

### smol header
This is where I want to link to....

# Biggest header 3

### smol header

Obsidian_P1JfgHStDj

4 Likes

Well, I had no idea! Thanks! It’s actually in the help too, I haven’t read it yet. Internal links - Obsidian Help

Thanks to @ariehen for showing me the way! I wrote a PowerShell function to streamline this.

It returns the URI to open Obsidian by default, but also optionally takes a vault path, note path, and heading contents, and forms the URI to that location. Further, you can hook this up to a command in Obsidian Shell Commands that you can invoke upon selecting an entire heading (excluding the leading hashes), and configure it to redirect output to the clipboard. Be sure to replace <MY_VAULT_NAME> with your vault. The kicker is that Obsidian Shell Commands will populate the command with the double-curly-braced variables, almost fully automating this link copying behavior.

You could probably refine this command to be a bit more intelligent about input, but it works well for me, as is!

C:/path/to/functions.ps1:

<#.SYNOPSIS
Custom functions.
#>

function Get-ObsidianUri {
    <#.SYNOPSIS
    Get URI to open Obsidian, optionally to a specific vault, file, and heading.
    #>
    Param([string]$Vault, [string]$File, [string]$Heading)
    function escape {Param($s)[uri]::EscapeDataString($s)}
    $v = ($Vault) ? "open?vault=$(escape($(Split-Path $Vault -Leaf)))" : ""
    $f = ($v -and $File) ? "&file=$(escape($File))" : ""
    $h = ($f -and $Heading) ? "%23$(escape($Heading))" : ""
    Write-Output "obsidian://$v$f$h"
}

Shell command:

. "C:/path/to/functions.ps1" && Get-ObsidianUri {{vault_path}} {{file_path:relative}} {{selection}}
1 Like

I guess I missed the edit window on my comment above, sorry to bump again just to make a correction, but the following instruction is no longer necessary in the above.

The resulting URI from running my script is a standard obsidian:// URI, but this shell-dependent command won’t work on mobile of course. The Advanced URI plugin gives you a custom obsidian://advanced-uri-prefixed URI and links to headers, but it’s a bit non-obvious. Your cursor needs to be inside a heading, then running the Advanced URI: copy URI for current file command will link directly to the heading instead of just the file. See the discussion about that.

1 Like