follow link on internet with vim

29 views
Skip to first unread message

Mathieu Roux

unread,
Jul 9, 2019, 8:56:36 AM7/9/19
to vim...@googlegroups.com
Hello,

Is it possible to follow a link with vim? for exemple, if my cursor is
on https://fr.wikipedia.org/wiki/Vim
i want to use my browser to go to this website.

By the same way, i can open a file with "gf" if my cursor is on the
file's name. But i don't know how to follow a link.

Best regards,
Mathieu

Ruben Safir

unread,
Jul 9, 2019, 9:06:12 AM7/9/19
to vim...@googlegroups.com
ph please don't add a browser to VIM


--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

Tony Mechelynck

unread,
Jul 9, 2019, 9:32:52 AM7/9/19
to vim_use
I don't know if it is possible, but I know where to find the answer:

:help netrw


Best regards,
Tony.

Suresh Govindachar

unread,
Jul 9, 2019, 9:54:30 AM7/9/19
to vim...@googlegroups.com, Mathieu Roux
On Windows, when the following lines are in vimrc, the stuff below the
cursor can be opened with the default browser by hitting "\x" (below,
the "essential" characters that come after noremap need to be in the
same line):

"eXecute string below cursor
nnoremap \x :silent !start rundll32 url.dll,FileProtocolHandler <cWORD>
" eXecute string below cursor after prepending it with path to file
nnoremap \xp :silent !start rundll32 url.dll,FileProtocolHandler
%:p:h/<cWORD>

Bill Hudacek

unread,
Jul 9, 2019, 10:59:18 AM7/9/19
to 'Vanilla Ice' via vim_use, Mathieu Roux
In Linux, I use this - mapped to Alt-Z- I put it in one my my vim
startup files. This command sequence may not work if you try to do it
interactively (but you can play with it to find out what does work):

map ú mzlB"lyE:!o <16><12>l &<CR>;

Explained:

ú        is alt-z- Enter this using control-V, then Alt-Z if you use
same shortcut key as I do...(I avoid multi-key entry for stuff I use
most often)

mz           set mark 'z' for later return

l            move one char to right if possible
B            move cursor backward one big-word (to start of URL)

"lyE         capture big-word into register 'L'

:!xdg-open   go to Ex: command line, use xdg-open to process the
following arg(s)...

<16><12> In your chosen vimrc/other startup file, type control-V,
control-R

l & This inserts register L contents (which you will insert using
Control-R above)

The ampersand is important! In my linuxboxes (ubuntu, fedora, RHEL)
the command will not work without it. I do not know why.

Hope this helps.

--

Kind Regards,

Bill Hudacek
Master Certified IT Architect

All opinions are my own, of course.


Enno

unread,
Jul 9, 2019, 11:09:16 AM7/9/19
to vim_use
Le mardi 9 juillet 2019 10:32:52 UTC-3, Tony Mechelynck a écrit :
> On Tue, Jul 9, 2019 at 2:56 PM Mathieu Roux wrote:
> >
> > Hello,
> >
> > Is it possible to follow a link with vim? for exemple, if my cursor is
> > on https://fr.wikipedia.org/wiki/Vim
> > i want to use my browser to go to this website.
> >
> > By the same way, i can open a file with "gf" if my cursor is on the
> > file's name. But i don't know how to follow a link.
> >
> > Best regards,
> > Mathieu
>
> I don't know if it is possible, but I know where to find the answer:
>
> :help netrw
>
>
> Best regards,
> Tony.

Thus, if elinks is installed, then typing `gf` will open the link as text in Vim.
Typing `gx` will open it with the program attached to links in the OS. On Linux, if one does not use Gnome or KDE desktop environment, then adding

let g:netrw_browsex_viewer = "xdg-open"

to the vimrc seems necessary.

Pete Doherty

unread,
Jul 9, 2019, 1:03:40 PM7/9/19
to vim_use
Both `gf` and `gx` worked for me as described using Debian/i3 (without having to set `g:netrw_browsex_viewer`).

Thanks for sharing this simple solution, Enno!

PRD

Ruben Safir

unread,
Jul 10, 2019, 12:05:22 AM7/10/19
to vim...@googlegroups.com
this is stupid. Use a WP

Mathieu Roux

unread,
Jul 10, 2019, 4:53:21 AM7/10/19
to vim...@googlegroups.com
Thanks everybody for your answers.

In fact, without doing anything, gx works on my laptop!
> --

Reply all
Reply to author
Forward
0 new messages