[vim/vim] VIM fails to properly read file URI with g + x (#7856)

34 views
Skip to first unread message

Žiga Lausegger

unread,
Feb 16, 2021, 7:02:26 AM2/16/21
to vim/vim, Subscribed

  • Vim version: 8.1
  • OS: Debian 10 -- 4.19.171-2 (2021-01-30) x86_64 GNU/Linux

Steps to reproduce

If I open any kind of C source file and create a comment like this:

// EXAMPLE 1: ../../example.pdf

If I position cursor over the file path and press g+x file is opened by a default OS PDF viewer. So I conclude that relative file paths are found and opened corectly.

If I create a (file) URI like this the file is also opened:

// EXAMPLE 2: file:///home/ziga/example.pdf

But if I create a (file) URI like this, file is only opened, but not on the page 10.

// EXAMPLE 3: file:///home/ziga/example.pdf#page=10

Expected behaviour

I expect Nvim to properly treat URI's and open PDF at the specified page... This is extremely important for documentation purposes.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
Feb 16, 2021, 7:18:13 AM2/16/21
to vim/vim, Subscribed

How would netrw be able to tell your pdf viewer on which page the document should be opened? For example, I'm using zathura(1) which supports a -P/--page option. You might use a different pdf viewer, which uses a different option, or maybe it doesn't even support the feature at all. AFAIK, netrw uses xdg-open(1); I don't think the latter can open a pdf at a specific page.

lacygoill

unread,
Feb 16, 2021, 7:19:37 AM2/16/21
to vim/vim, Subscribed

I expect Nvim to properly treat URI's and open PDF at the specified page... This is extremely important for documentation purposes.

s/Nvim/Vim/

Christian Brabandt

unread,
Feb 16, 2021, 7:40:47 AM2/16/21
to vim/vim, Subscribed

what pdf reader are you using?

Christian Brabandt

unread,
Feb 16, 2021, 7:43:03 AM2/16/21
to vim/vim, Subscribed

gx is a keymapping provided by the distributed plugin netrw. It might help to follow the steps outlined at :h netrw-debug

K.Takata

unread,
Feb 16, 2021, 7:47:34 AM2/16/21
to vim/vim, Subscribed

And it might be better to try the latest version of netrw:
http://www.drchip.org/astronaut/vim/#NETRW

lacygoill

unread,
Feb 16, 2021, 8:17:00 AM2/16/21
to vim/vim, Subscribed

FWIW, I've just pushed a commit to take into account a page number when opening this kind of links. It requires a recent Vim and zathura(1).

Žiga Lausegger

unread,
Feb 19, 2021, 3:08:11 AM2/19/21
to vim/vim, Subscribed

@lacygoill Thank you very much! I belive this will be of great benefit to all the VIM users!

Žiga Lausegger

unread,
Nov 25, 2021, 4:42:15 AM11/25/21
to vim/vim, Subscribed

I tested this today with nvim and vim and still URI (as a standard) don't work entirely. I tested them more thoroughly and I am sending in the attachment my results (URI -- testing.pdf)!

It would really be beneficial to implement URIs correctly as per the attached standard (RFC-3986 -- URI.pdf). It is really awkward & weird if some URIs work while others don't. Feeling is just completely wrong...
URI -- testing.pdf
RFC-3986 -- URI.pdf


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Christian Brabandt

unread,
Nov 25, 2021, 5:30:22 AM11/25/21
to vim/vim, Subscribed

For one, I think adding additional parameters for the default gx key mapping is currently not supported by
netrw, so you may try to use @lacygoills vim-gx plugin.

I am not sure, if this issue belongs here.


You are receiving this because you are subscribed to this thread.

Christian Brabandt

unread,
Nov 25, 2021, 5:34:15 AM11/25/21
to vim/vim, Subscribed

I also think it may depend on whatever viewer (for each document type) you are using, since you may need to pass additional parameters to jump to the correct chapter/page, etc


You are receiving this because you are subscribed to this thread.

Žiga Lausegger

unread,
Nov 25, 2021, 5:46:19 AM11/25/21
to vim/vim, Subscribed

@chrisbra It would be really nice if vim would by default properly reference URI. It feels buggy if some URI work and some don't. I don't like to depend on the plugin (e.g. vim-gx) but will at this point use whatever in order to have a functional editor...


You are receiving this because you are subscribed to this thread.

Žiga Lausegger

unread,
Nov 25, 2021, 5:52:29 AM11/25/21
to vim/vim, Subscribed

@chrisbraCould this be programmed automatically using the vim setup file? I am currently using this settings to point netrw to the right directions:

"*******************************************************************************
" PLUGIN ASYNCRUN & NATIVE NETRW
"*******************************************************************************

" remove default header for built-in netrw file manager
let g:netrw_banner=0

" make sure that viewer is selected according to the suffix.
let g:netrw_browsex_viewer="-"

" functions for file extension '.md'.
function! NFH_md(f)
    call asyncrun#run("", "cwd", "typora " . a:f)
endfunction

" functions for file extension '.pdf'.
function! NFH_pdf(f)
    call asyncrun#run("", "cwd" , "evince " . a:f)
endfunction

" functions for file extension '.html'.
" NOTE: Append '/index.html' to URLs which do not end with '.html'.
function! NFH_html(f)
    call asyncrun#run("", "cwd", "firefox --new-window " . a:f)
endfunction

" functions for file extension '.mp4'.
function! NFH_mp4(f)
    call asyncrun#run("", "cwd", "mpv " . a:f)
endfunction

" functions for file extension '.pro'.
function! NFH_pro(f)
    call asyncrun#run("", "cwd", "kicad " . a:f)
endfunction

" functions for file extension '.sch'.
function! NFH_sch(f)
    call asyncrun#run("", "cwd", "eeschema " . a:f)
endfunction

" functions for file extension '.kicad_pcb'.
function! NFH_kicad_pcb(f)
    call asyncrun#run("", "cwd", "pcbnew " . a:f)
endfunction


You are receiving this because you are subscribed to this thread.

Christian Brabandt

unread,
Nov 25, 2021, 6:05:50 AM11/25/21
to vim/vim, Subscribed

@chrisbra It would be really nice if vim would by default properly reference URI. It feels buggy if some URI work and some don't. I don't like to depend on the plugin

For one, not everything needs to be implemented in Vims core (using C). If a plugin can be made to work, then why not use it? I think it will be almost impossible to handle parameters to URI properly, because they will require additional parameters to whatever program you are using to view those URIs.

but will at this point use whatever in order to have a functional editor...

Well first, whether or not parsing optional parameters for URIs is considered a requirement for a functional editor can be debatable. And then of course Vim and all of its plugins it is open source. If you want to improve the state of things, please help by contributing patches to fix those. This is your chance to contribute to a well-known Open Source project.

" functions for file extension '.pdf'.
function! NFH_pdf(f)
    call asyncrun#run("", "cwd" , "evince " . a:f)
endfunction

This of course needs asyncrun, an additional dependency. And then does evince support additional parameters to jump to a separate section? And how do you call that function?


You are receiving this because you are subscribed to this thread.

Žiga Lausegger

unread,
Nov 25, 2021, 6:49:49 AM11/25/21
to vim/vim, Subscribed

@chrisbra Explanation to how these functions are used is from the vim's :help netrw command where I found this section:

When |g:netrw_browsex_viewer| exists and is "-", then netrw will attempt to
handle the special file with a vim function.  The "x" map applies a function
to a file, based on its extension.  Of course, the handler function must exist
for it to be called!
>
 Ex. mypgm.html   x -> NFH_html("scp://user@host/some/path/mypgm.html")

<	Users may write their own netrw File Handler functions to
	support more suffixes with special handling.  See
	<autoload/netrwFileHandlers.vim> for examples on how to make
	file handler functions.   As an example: >

	" NFH_suffix(filename)
	fun! NFH_suffix(filename)
	..do something special with filename..
	endfun
<
These functions need to be defined in some file in your .vim/plugin
(vimfiles\plugin) directory.  Vim's function names may not have punctuation
characters (except for the underscore) in them.  To support suffices that
contain such characters, netrw will first convert the suffix using the
following table: >

    @ -> AT       ! -> EXCLAMATION    % -> PERCENT
    : -> COLON    = -> EQUAL          ? -> QUESTION
    , -> COMMA    - -> MINUS          ; -> SEMICOLON
    $ -> DOLLAR   + -> PLUS           ~ -> TILDE
<
So, for example: >

	file.rcs,v  ->  NFH_rcsCOMMAv()
<
If more such translations are necessary, please send me email: >
		NdrOchip at ScampbellPfamily.AbizM - NOSPAM
with a request.

Associated setting variable: |g:netrw_browsex_viewer|

And I implemented everything according to the official help guide.


You are receiving this because you are subscribed to this thread.

Bram Moolenaar

unread,
Nov 25, 2021, 9:56:50 AM11/25/21
to vim/vim, Subscribed

Opening arbitrary files with another program is not a core task of Vim. It's nice that some things work, mostly added because someone wanted it. There is no goal to be comprehensive. Ideally Vim just has a way to forward the name to a system "open" function. But you can always add your own tweaks or add someone's plugin.
If you want to make improvements to netrw, contact the maintainer.


You are receiving this because you are subscribed to this thread.

Bram Moolenaar

unread,
Nov 25, 2021, 9:56:52 AM11/25/21
to vim/vim, Subscribed

Closed #7856.


You are receiving this because you are subscribed to this thread.

Reply all
Reply to author
Forward
0 new messages