This vim plugin automatically finds and inserts URLs for links in Markdown and ReST documents. You can use a search engine (DuckDuckGo) or the current tab in Safari or Chrome.
Search for URLs
For example, say you have this document:
I think [Markdown] is really great. [Markdown]: need a URL for this
With your cursor on the last line, you can type
auto-complete link) and the last line will become:
Behind the scenes, the plugin searches on DuckDuckGo for the word "Markdown" and
inserts the first result's URL, a reasonable guess for a relevant link on the
subject, in the appropriate place. This also works in ReST documents on
hyperlink target lines like
.. _Markdown: link goes here.
Create Link Definitions
This plugin can help you insert the markup for reference-style links. For example, suppose you have just typed this paragraph:
I prefer the [vim text editor][vim].
<leader>am (for auto-make link) to add a definition for the link
below the current paragraph:
I prefer the [vim text editor][vim]. [vim]:
This also works in ReST for reference-style links like
The plugin is careful to insert newlines between text paragraphs and blocks of link references to make your document look nice.
Grab a Browser Tab
You can also grab the URL for your browser's current tab and insert that. (This
currently works for Safari and Chrome and only on OS X.) Just type
<leader>aB and the URL will appear (magically!) at your cursor.
All Together Now
To insert and complete a link definition in one fell swoop, use
(for auto-link, the name of this plugin). This will add a reference to your
link after the current paragraph, fill it out with a search result, and then
jump back to your current cursor position to let you keep writing. (If your
\, then it's like typing
To do this with your browser's foremost tab instead, type
b is for browser).
Bonus: Open a Search
Sometimes, you aren't feeling lucky. To open the current link's keys as Google search terms, type
\as for auto-search. You can then click the result you want and flip back to
\ab to insert the page you find.
The plugin requires vim to be built with Python bindings.
If you're using Pathogen, just clone this repository into
your bundles directory (and run
:Helptags). Otherwise, place files in
doc into the corresponding directories in
- Automatic activation when completing a link reference (i.e., after typing
- Optionally use the link text, rather than the reference ID, as the search terms.
- Options to use subsequent results (if the first link isn't good).
- Handle web service errors (avoid inserting "None", possible retry).
This plugin is by me, Adrian Sampson. This is my first bit of vimscript hackery and is very experimental---I apologize for weirdnesses arising from my unfamiliarity with writing vim plugins.
Jim Kalafut is responsible for switching the plugin over from the defunct Blekko API to DuckDuckGo. Thanks, Jim!
The code is available under the MIT license.