Link to Search Results

Is it possible to add a link to a search result within a document &, and if so, what would be the code for that?

1 Like

Hi. You can embed a search in a note like this:


```query
SEARCHTERMGOESHERE
```

I know that’s not quite what you asked for, but might be a good solution for you.

1 Like

In the note, add three backticks then the word query on a line. Then, on the next line paste your search query. This can simply be copied from the search field for the search you want to embed. Finally, on the next line close the block by adding three backticks. It should look something like this:


```query
(paste search query here)
```

In the Obsidian Help, you can read about it on a page about Search.

Good luck.

1 Like

Yeah, I know about that feature. I was hoping there was a way to just do a link though.

1 Like

@glor One workaround would be to use a program like AutoHotkey to build a simple little macro that would copy the current line the cursor is on, trigger your hotkey for Search:search in all files, then trigger the pasting of the copied line thus beginning the search. Rather than having a link to the search in your note, you could simply have the cursor on the line with the query and press the trigger for your macro. In order to avoid the search query actually adding any tags to your note, you might want to enclose the query in a codeblock.

For example, if your search was for tag:#status/active OR tag:#status/closed you could add the query in your note like

```
tag:#status/active OR tag:#status/closed
```

After installing AutoHotkey (if on Windows), you could just right click and choose New>AutoHotkey script and in the file below the stuff that is automatically added up top, you could do something like:

^!+5::
Send, ^c
Send, !+f
Send, ^v
return

This script would trigger Ctrl+c , Alt+Shift+f , then Ctrl+v whenever you press Ctrl+Alt+Shift+5. I should note that this works for me because I have my Search:search in all files set to Alt+Shift+f. I should also mention that this works because when you press Ctrl+c or even Ctrl+x in Obsidian, it copies or cuts the entire line that the cursor is on.

I know this might not be worth it in this exact instance. But a while back I was introduced to AutoHotkey here on the forum, and ever since I have found countless ways to automate repetitive tasks when working within Obsidian and other software. I hope you find this helpful.

Good luck.

Any possibility that we create separate notes - one note which has search/query and another note to “links/embed” this query

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.