Add "Copy Wikilink" command

Use case or problem

You can copy an Obsidian URL with a command. But there is no way to copy a Wikilink. It would be a great way to quickly grab a link from one note, and drop it into another.

Proposed solution

Add a bindable command, “Copy Wikilink”. It would copy the user’s Wikilink format, and obey the user’s settings for path format. (Shortest when possible, absolute, etc.)

A hotkey/command would even help to avoid having to know and search the name of a note. When adding a link via auto-complete search.

Current workaround (optional)

The different ways now:

  • Drag from the file explorer
  • Start typing a wikilink, and search for the name
  • “Copy file path” command, and then manually reformat it from Path/Note.md to [[Note]]

Related feature requests (optional)

Unanswered help request: Hotkey to copy wiki link

Related FR about dragging from note tabs: Allow for dragging of note icon or tab to create link

8 Likes

related to https://forum.obsidian.md/t/command-palette-right-click-menu-item-to-generate-block-and-header-reference/16352

3 Likes

Use case or problem

I want to quickly copy a note link to another note. Currently, I have to type the [[ ]]'s and type out the note. Many of my notes have the same title distinguished only by their folder (e.g. “SE108/Kolb’s 10” vs. “SE73/Kolb’s 5”). This makes the current system almost hopeless.

I thought I had something with the “Copy Obsidian URL”, but that’s for “external sources coming in”. It’s not internal friendly.

Obsidian_oX22iZu4Se

Proposed solution

Either have an explicit option, or auto-convert Obsidian URL’s into internal links when pasted into an Obsidian note.

Current workaround (optional)

I tried looking for community plugins, but I didn’t see any. I tried simply using the Obsidian URL, and then when I needed to visit the note, copy and paste it into a browser, but that was not comfortable.

Related feature requests (optional)

I saw this request… but this person wants the exact opposite of what I’m trying to do ha. Context menu to convert internal links to obsidian url links within editor

You may already know this, but you can type folder names in the link (but you have to type the whole path without much help, which may be why you find hopeless). There’s a feature request or two asking to improve that (by for example using Tab to complete folder paths) which you can upvote.

In my experience apps in general just don’t support this as well as they should, so personally I’ve given up on it and only use unique names in my vault. As a side benefit, my note names tend to be clearer now. (I realize this may still sound unappealing.)

1 Like

Instead of asking to transform an Obsidian URL to a wikilink, why not ask to make a wikilink? It’s one less step. Anyway, moved to this already existing FR.

1 Like

Having this functionality natively in Obsidian would be the preferred way for me too, meanwhile, one of the easiest but most feature complete approaches is to use the following snippet with the excellent obsidian-user-plugins.

No need to create any files, just install the plugin, activate it and paste the following code into a new Snippet:

plugin.addCommand({
    name: 'Copy WikiLink to Clipboard',
    callback: () => {

        const noteFile = plugin.app.workspace.getActiveFile(); // Currently Open Note
        if (!noteFile.name) return; // Nothing Open

        // Copy WikiLink to clipboard
        navigator.clipboard.writeText("[[" + noteFile.basename + "]]");
    }
});

You can then add the new command to any place where commands can be added, including hot keys, menus, sidebar, etc.

This is vey basic and assumes unique file names in the Vault resp. does not put the path of the file within the Vault in the WikiLink. If you need something more feature complete you could expand the code quite easily to test for duplicate file names under different paths and then copy the WikiLink with the path in the Vault or to copy the path in any case and use the display title feature of the WikiLink Syntax.

Here’s as slightly revised version – I had missed the “id” completely which creates issues if you use more than one snippet / script with obsidian-user-plugins:

  plugin.addCommand({
    id: "copy-wikilink-to-clipboard",
    name: "Copy WikiLink to Clipboard",
    callback: () => {
      const noteFile = plugin.app.workspace.getActiveFile(); // Currently Open Note
      if (!noteFile.name) return; // Nothing Open

      // Copy WikiLink to clipboard
      navigator.clipboard.writeText("[[" + noteFile.basename + "]]");
    },
  });

+1 this would be a great addition. Also having the option to right click a file in your file explorer and clicking a “copy wikilink” option would be awesome.

1 Like

+1

Need this!