Select Many Lines to Create Separate Links

Another option is to first make a backup, then use the Replace functionality within VSCode. Regex will need to be enabled. To do this, click on the .* icon in the dialog (see image at the bottom). Then in the search field at the top, add:

\n(..*$)

And, in the lower field, add:

[[$1]]\n


To be clear, I am definitely not an expert. But, I will explain the regex, since it isn’t overly complicated. And, like anything else on a computer (and in life), beware that there could be unintended results, so make a backup before experimenting. Anyways, while it isn’t necessary to fully understand the regex, it may be useful to help avoid doing something destructive, or to potentially use as a starting point for anyone new to regex. See this link: Regular Expressions in Obsidian (copied from mdn web docs) for more information about regex in Obsidian search.

Within the search field at the top, the regex matches a new line with \n. Then the parentheses are used to contain the text that matches the regex within the parentheses. This is a capturing group. Within the parentheses, the first . is there to make sure that there is at least one character on the line. Then, the .* will continue to select anything for the rest of the note. In order to prevent this, the $ is added. The $ causes the regex to only match the preceding pattern until the end of the line.

Within the replace field on the bottom, the opening brackets are added. Then, the $1 returns the text that was matched within the first (and only) capturing group of the search. So, the entire text from each line are returned. The closing brackets are added next. And, finally, so that all of the links are not returned as a continuous string, the \n is added. This starts a new line for each of the replacements.

It should look like the attached image here:

I hope this helps! Good luck! Be careful!

3 Likes