gvim windows netrw filehandler html elinks configuration

99封情书 提交于 2019-12-12 02:49:55

问题


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


回答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.




回答2:


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




回答3:


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).



来源:https://stackoverflow.com/questions/26632841/gvim-windows-netrw-filehandler-html-elinks-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!