Closed ctittel closed 4 years ago
gx
is the default mapping of netrw builtin plugin and there is no clear way to pass it a correct URL unless I remap gx
providing my own implementation.
Didn't plan but will look into it.
I see! Is there currently an alternative command which opens adoc links correctly?
I see! Is there currently an alternative command which opens adoc links correctly?
I don't know. I for myself do not use netrw, so I was planning to implement it and even started some times ago:
"" Open URL under cursor using OS
"" http://ya.ru
"" ~/docs
"" $HOME/docs
"" C:/Users/maksim.kim/docs
"" .
func! os#open_url(word) abort
" Windows only for now
if !has("win32")
return
endif
let word = a:word
if word =~ '^[~.$].*'
let word = expand(word)
endif
" TODO: check if barebone url
" TODO: check if path or a filename
" TODO: check and extract asciidoctor url
" TODO: check and extract markdown url
exe printf("silent !start %s", word)
" nnoremap gx :call job_start('cmd.exe /c start '.expand("<cfile>"))<CR>
endfunc
But didn't have a time to do it.
Thanks for the answer!
I don't know much vimscript (yet), but here is some additional information which might be useful:
Markdown plugins (probably) also have the same problem with gx
and custom link formats.
I have plasticboy/vim-markdown in my vimfile and it seems to be able to handle custom links correctly with ´gx´. I tried these two formats which both work correctly:
<https://whatever.com>
and
[file:zettelkasten.md](zettelkasten.md)
In the latter example gx
opens the correct file no matter on which character in the string the cursor is - you can be on the first [
or last )
or anywhere inbetween.
Could you check latest master?
Hi, I tested some links in my adoc files.
In my tries, links of the form https://example.com[Text]
and https://example.com/whatever
seemed to work correctly :)
But some problems I have found:
https://noteself.org/[Note Self]
: If the cursor is on or between the first h
and the e
in Note
, gx
opens the correct website. But on the rest of the string it doesn't work.https://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU
(probably because of the #
)http://
part is missing it doesn't work (example: www.google.com[test]
)file://file.adoc
and file:file.adoc
yep, it is not very robust at the moment.
https://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU
this one is strange, indeed. Will checkwww
doesn't work and actually is not highlighted in asciidoctorfile://
-- will add itfile://
andhttps://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU
should now workCool :)
Here is the relevant section from the AsciiDoctor Reference: https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#links
For file links AsciiDoc uses two ways:
link:index.html[Docs]
for relative fileslink://
for absolute linksfile://
works for me for absolute links.
A minor problem with the previous link:
I have (https://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU)
in my adoc file. When doing gx
on it it now opens https://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU)
(Parantese too much)
But this probably doesn't matter as one can just add a space after the link.
I have
(https://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU)
in my adoc file. When doinggx
on it it now openshttps://groups.google.com/forum/#!topic/tiddlywiki/lIS6sFbrpwU)
(Parantese too much)
This I wouldn't be able to fix. (simple problem --> quite unobvious solution)
link:index.html[Docs]
for relative fileslink://
for absolute links
Will have a look into this
link:index.html[Docs]
for relative fileslink://
for absolute linksWill have a look into this
should now also work.
Bear in mind that link:index.html[Docs]
would only work if your vim working directory is the same.
* There are issues if there are spaces in the link description, e.g. with `https://noteself.org/[Note Self]`: If the cursor is on or between the first `h` and the `e` in `Note`, `gx` opens the correct website. But on the rest of the string it doesn't work.
I will try to implement it this week. Although I am not sure about implementation yet, and whether I would be able to do it :)
Could you check latest master?
I think I have fixed "cursor is on [description separated with spaces]"
Great work! :)
The fix for spaces in the link title worked well for me.
Also I think its very cool that file link
's are always opened in the system default application.
But I have some issues with link:
:
link:vim.adoc
nor link://
are recognized as links when the [link title]
is missinglink:Keybinds\\2020-04-01_20-06-29_EmacsIcon.svg[Test]
. When I use /
or //
for the subdirectory path instead, it doesn't work. This may create issues when switching between Linux and Windows.Thx for input, will check it tomorrow
- neither
link:vim.adoc
norlink://
are recognized as links when the[link title]
is missing
This is actually not a valid asciidoctor syntax. link
should be accompanied with []
- directory paths: On my windows computer, only this path works for opening a file in a subdirectory:
link:Keybinds\\2020-04-01_20-06-29_EmacsIcon.svg[Test]
. When I use/
or//
for the subdirectory path instead, it doesn't work. This may create issues when switching between Linux and Windows.
forward slash:
link:C:/Users/maksim.kim/test.txt[test file]
link:misc/aseprite.adoc[aseprite installation]
Under the hood it just calls :!start misc/aseprite.adoc
(or !open
, !xdg-open
for other oses) and for some reason it fails.
I have tried to change current dir with lcd
but it has no effect.
Hmm, looks like I did it :)
Pls, try latest master
Very cool, works perfectly :) Great work
Here are some very advanced usecases from the quick reference that probably not many use (if the goal is to implement the specification perfectly):
link:++https://example.org/?q=[a b]++[URL with special characters]
<<paragraphs>>
<<document-b.adoc#section-b,Section B>>
The last two are probably not very important as Vim has strong navigation features inbuilt anyways, but I just want to mention them ;)
The last two are probably not very important as Vim has strong navigation features inbuilt anyways, but I just want to mention them ;)
Yep, do not plan to do anything like that. At least for now. Thx!
gx
is the default command from Vim 7.4 to open URLs (see https://stackoverflow.com/questions/9458294/open-url-under-cursor-in-vim-with-browser).I have the following line in a .adoc file opened with Vim:
When doing
gx
on this line in normal mode, vim opens the clearly wrong URLhttps://www.brainlinks-braintools.uni-freiburg.de/rss-2020-workshop/[Interesting/
in the browser. Removing the trailing / in the vim link doesn't help.