demo_extract_and_open_nearest_url.mp4
This setup allows you to open URLs in your web browser from Vim without having your cursor exactly under the URL.
This is not a plugin, but a set of Unix filters following the philosophy: "Do one thing and do it well."
As such, there is no automated installation process. You will need to manually install the scripts and configuration. But don't worry, it's very simple and takes less than a minute.
I wrote a small blog post on my website that more or less repeats what's written here, but with more details.
To open a URL in your web browser, just place the cursor near the URL and press gx
. There is no need to have your cursor exactly under the URL.
You can customize the keybind, but it uses gx
by default.
Either by cloning the repository:
git clone https://github.com/sderev/vim-url-opener.git
Or by downloading the files directly:
curl -O https://raw.githubusercontent.com/sderev/vim-url-opener/main/scripts/extract_nearest_url && \
curl -O https://raw.githubusercontent.com/sderev/vim-url-opener/main/scripts/add_this_to_your_vimrc.txt && \
curl -O https://raw.githubusercontent.com/sderev/vim-url-opener/main/scripts/brave
- Copy the
extract_nearest_url
script to a directory in yourPATH
. For example:~/usr/local/bin
. - Copy the
brave
script to a directory in yourPATH
. - Edit the
brave
script and replace the path to your own web browser.- Rename the script to match the name of your web browser.
- You will also now be able to open URLs in your web browser from your terminal:
brave https://example.com
.
- Add the content of
add_this_to_your_vimrc.txt
to your.vimrc
.- Change the
brave
command to the name of the script you created in step 3. - Change the keybind if you want to use something other than
gx
.
- Change the
That's it.