0

I'm using gvim 7.3, MS-Windows 32-bit GUI version with OLE support

I'm attempting to configure the netrw filehandler to open locally saved .html files in with the elinks browser, rather than the firefox browser. The help file for netrw refers to a setting that can be placed in the .vimrc file:

:let g:netrw_browsex_viewer= "  "

it also says that

'for Windows 32 or 64 the url and FileProtocolHandler dlls are used'.

I've tried entering the filepath to the elinks executable between the quotes, but no result. My internet searches so far haven't revealed any practical examples of how to work with url and FileProtocolHandler dlls in vim.

I would be very grateful for any help.

GilF

user2962912
  • 69
  • 1
  • 6

3 Answers3

1

This allows you to launch correct file viewer for all kinds of files: (powerpoint ppt, excel xls, chrome html, vlc on video) and whatever windows explorer has association for. On windows7, put the batch file expl2.cmd in your vim path.

In vimrc put

:let netrw_browsex_viewer='expl2.cmd'

In gvim use gx on cfile to launch explorer.exe, it will launch correct viewer, e.g. powerpoint,firefox,chrome. Notes: The second line converts forward slashes to backslashes. If you have spaces in your filename, vim won't expand cfile.

c:> cat expl2.cmd

set file=%1
set file=%file:/=\%
start explorer.exe /n,/e,/root,%file%

I also wrote this answer in gvim Windows 7 netrw open url under text cursor as it comes up first in google.

Community
  • 1
  • 1
mosh
  • 1,402
  • 15
  • 16
0

Are you trying to "edit" the html file (ie. :e somefile.html)?

Try putting

:let g:netrw_http_cmd= "path_to_elinks"

in your .vimrc

user21497
  • 1,061
  • 8
  • 9
  • Wouldn't that only work for viewing (not editing) remote files? netrw_http_cmd indicates that it's for protocol resolution. I guess it would work for http://localhost/somefile.html. – idbrii Nov 06 '14 at 17:01
0

g:netrw_browsex_viewer is for defining a generic program to open stuff with. So while it might work to point it to elinks for html files, it will break jpg/pdf/etc files. On Windows, it may be most appropriate to use 'start' which uses Window's file associations. Since that's not a real program, you can make a batch file:

start %*

Put that in c:\stuff\magicopen.bat and let g:netrw_browsex_viewer = 'c:/stuff/magicopen.bat' (The path doesn't matter, but the forward slashes do!)


Alternatively, you can use netrw's netrw_filehandler:

"" Tell netrw to use internal filehandlers if possible
let g:netrw_browsex_viewer= "-"
"" Define an html filehandler
function! NFH_html(filename)
    execute ':!start elinks '. a:filename
endf
"" Just in case, handle htm files too
function! NFH_htm(filename)
    call NFH_html(a:filename)
endf

Change the internals of NFH_html as needed (absolute path to elinks, invocation arguments, add more !start options -- see :help !start).

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • Thank you idbrii. Yes using a bat file is a smart quick fix. Netrw filehandler functions would also be an appropriate broader solution. – user2962912 Nov 20 '14 at 18:04