ILoveCheezits
ILoveCheezits

Reputation: 87

How do you hyperlink text in vim editor?

I need to set some text to be hyperlinked to a website via the vim editor. How do I accomplish that?

Upvotes: 4

Views: 11487

Answers (2)

Shawn
Shawn

Reputation: 199

If you don't require a link that can be "clicked" with a mouse and don't mind having some extra text showing you can use the utl (universal text link) plugin. Get the details at https://www.vim.org/scripts/script.php?script_id=293. It is old, but still works for me. To link to google for instance the text would have < url:www.google.com > in the text. To use the link, move your cursor somewhere on or between the brackets and input \gu from command mode. This will cause your browser to go to Google's site. Of course there is some setup in the utl_rc.vim file to point it at your browser.

I should also note that you can use this to move between text files, or within a file as well. The details are at the link I gave above.

Upvotes: 2

Martin Tournoij
Martin Tournoij

Reputation: 27822

Vim is not a word processor. Vim displays text exactly as it is on the disk. You can do some minor "formatting" of text such as folding lines, syntax highlighting, concealing a few characters, but that's it. None of this information is actually stored in the file itself, instead, it is applied from "outside the file" with Vim. This is different from .doc files, where the formatting is stored in the file.

Note that gx opens links. Perhaps this is what you want?

What you want can maybe be done with:

  • A conceal pattern combined with some custom mappings. I haven't tried doing this, but it's probably possible.

  • The only way to "link" something in Vim is to another file using tags. See :help tags-and-searches. Perhaps this feature can be abused into opening web pages, I don't suggest that you try.

In short, you're trying to use Vim for a task it wasn't really designed to do, so doing that will be hard and ugly, if possible at all.

Upvotes: 4

Related Questions