Open URL in Vim

4.6
(50)

Did you know you can open a URL in Vim directly from the command line? That’s right, you can simply call vim https://some/path and you’ll instantly be able to view and edit the results in Vim. When you open a URL in Vim this way, it uses native functionality that is provided by the netrw plugin, a plugin that ships with Vim therefore is available to everyone.

Once you’ve opened the contents in Vim, you can use gf on any other URL in that file to open its contents in Vim. In fact, you can press gf on a URL anywhere in Vim in any buffer to open its contents in the current window.

When is this useful? You could use this to get a quick peak at the HTML source for any publicly available web page. But it might be more useful for things like JSON endpoints. Think of it like curl but the results pop open in everyone’s favorite editor.

I recently had a perfect use case for this: Viewing the Sitemap XML file for a website. In the short screencast demo below, you can see I open the URL from the command line. (Vim even views the the gzipped file!)

Once I’m in that file, which is actually an XML index of other files, I can press gf to open one of the listed URLs the same way. From here, I used normal Vim techniques to browse, search, and filter, the XML file.

As a bonus, don’t forget you can use gx to open any URL in a browser.

How useful was this tip?

Average rating 4.6 / 5. Vote count: 50

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts