Sometimes I just need to reference the source of an HTML or CSS file online without writing to it. If I need to do this while I’m editing something else in
vim, my best course of action is to open a split in
vim and do it there. Even if I’m not working on said thing in
vim, that is the way that I’m most comfortable moving around in documents, so there’s still a good chance I want to open my source file there.
netrw, the default1 file explorer for
vim, handles HTTP and HTTPS. By default, it does this using whichever of the following it finds first:
fetch. At work, we’re going through an HTTPS transition, and at least for the time being, the certificates are… not quite right. Not sure what the discrepancy is (it’s not my problem), but strict clients are wary. This includes
wget. When I went to view files via HTTPS in
vim, I was presented with errors. This obviously wasn’t
vim’s fault, but it took a bit of doing to figure out exactly how these elements interacted and how to modify the behavior of what is (at least originally) perceived as
netrw opens up a remote connection, it essentially just opens up a temporary file, and runs a command that uses that temporary file as input or output depending on whether the command is a read or write operation. As previously mentioned,
netrw looks for
fetch. My cygwin install has
wget, but none of the others. It also has
lynx, which I’ll briefly discuss at the end. I don’t know if
links can be set to ignore certificate issues, but I don’t believe so.
wget can, however.
We set this up in
vim by modifying
netrw_HTTP_cmd, keeping in mind that
netrw is going to spit out a temporary file name to read in. So we can’t output to STDOUT, we need to end with a file destination. For
curl, we can very simply use
:let g:netrw_HTTP_cmd="curl -k". For
wget, we need to specify output, tell it not to verify certs, and otherwise run quietly:
:let g:netrw_HTTP_cmd="wget --no-check-certificate -q -O".
I don’t have an environment handy with
elinks, but glancing over the manpages leads me to believe this isn’t an option with either. It isn’t with
lynx either, but in playing with it, I still think this is useful: for a system with
lynx but not any of the default HTTP(s) handlers,
netrw can use
:let g:netrw_HTTP_cmd="lynx -source >". Also interesting is that
lynx (and presumably
elinks via different flags) can be used to pull parsed content into
:let g:netrw_HTTP_cmd="lynx -dump >".