runtime(netrw): make :Launch/Open autoloadable
fixes: #15959 closes: #15962 Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Konfekt <Konfekt@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
*pi_netrw.txt* For Vim version 9.1. Last change: 2024 Oct 27
|
||||
*pi_netrw.txt* For Vim version 9.1. Last change: 2024 Oct 31
|
||||
|
||||
------------------------------------------------
|
||||
NETRW REFERENCE MANUAL by Charles E. Campbell
|
||||
@ -1469,7 +1469,6 @@ With either form of the command, netrw will first ask for confirmation
|
||||
that the removal is in fact what you want to do. If netrw doesn't have
|
||||
permission to remove a file, it will issue an error message.
|
||||
|
||||
*netrw-gx* *Open* *Launch*
|
||||
CUSTOMIZING BROWSING WITH A SPECIAL HANDLER *netrw-x* *netrw-handler* {{{2
|
||||
|
||||
Certain files, such as html, gif, jpeg, (word/office) doc, etc, files, are
|
||||
@ -1479,7 +1478,7 @@ operating system). Netrw allows one to invoke such special handlers by:
|
||||
* hitting gx with the cursor atop the file path or alternatively x
|
||||
in a netrw buffer; the former can be disabled by defining the
|
||||
|g:netrw_nogx| variable
|
||||
* when in command line, typing :Open <path>
|
||||
* when in command line, typing :Open <path>, see |:Open| below.
|
||||
|
||||
One may also use visual mode (see |visual-start|) to select the text that the
|
||||
special handler will use. Normally gx checks for a close-by URL or file name
|
||||
@ -1490,47 +1489,54 @@ select the text to be used by gx by making a visual selection (see
|
||||
|visual-block|) and then pressing gx.
|
||||
|
||||
The selection function can be adapted for each filetype by adding a function
|
||||
Netrw_get_URL_<filetype>, where <filetype> is given by &filetype.
|
||||
`Netrw_get_URL_<filetype>`, where <filetype> is given by the 'filetype'.
|
||||
The function should return the URL or file name to be used by gx, and will
|
||||
fall back to the default behavior if it returns an empty string.
|
||||
For example, special handlers for links Markdown and HTML are
|
||||
>
|
||||
" make gx work on concealed links regardless of exact cursor position
|
||||
function Netrw_get_URL_markdown()
|
||||
" markdown URL such as [link text](http://ya.ru 'yandex search')
|
||||
try
|
||||
let save_view = winsaveview()
|
||||
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
|
||||
return matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
|
||||
endif
|
||||
finally
|
||||
call winrestview(save_view)
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function Netrw_get_URL_html()
|
||||
" HTML URL such as <a href='http://www.python.org'>Python is here</a>
|
||||
" <a href="http://www.python.org"/>
|
||||
try
|
||||
let save_view = winsaveview()
|
||||
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
|
||||
return matchstr(getline('.')[col('.') - 1 : ],
|
||||
\ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
|
||||
endif
|
||||
finally
|
||||
call winrestview(save_view)
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
" make gx work on concealed links regardless of exact cursor position: >
|
||||
|
||||
function Netrw_get_URL_markdown()
|
||||
" markdown URL such as [link text](http://ya.ru 'yandex search')
|
||||
try
|
||||
let save_view = winsaveview()
|
||||
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
|
||||
return matchstr(getline('.')[col('.')-1:],
|
||||
\ '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
|
||||
endif
|
||||
finally
|
||||
call winrestview(save_view)
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function Netrw_get_URL_html()
|
||||
" HTML URL such as <a href='http://www.python.org'>Python is here</a>
|
||||
" <a href="http://www.python.org"/>
|
||||
try
|
||||
let save_view = winsaveview()
|
||||
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
|
||||
return matchstr(getline('.')[col('.') - 1 : ],
|
||||
\ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
|
||||
endif
|
||||
finally
|
||||
call winrestview(save_view)
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
<
|
||||
|
||||
Other than a file path, the text under the cursor may be a URL. Netrw uses
|
||||
by default the following regular expression to determine if the text under the
|
||||
cursor is a URL:
|
||||
>
|
||||
g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
|
||||
:let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
|
||||
<
|
||||
Associated setting variables:
|
||||
|g:netrw_gx| control how gx picks up the text under the cursor
|
||||
|g:netrw_nogx| prevent gx map while editing
|
||||
|g:netrw_suppress_gx_mesg| controls gx's suppression of browser messages
|
||||
|
||||
OPENING FILES AND LAUNCHING APPS *netrw-gx* *:Open* *:Launch* {{{2
|
||||
|
||||
Netrw determines which special handler by the following method:
|
||||
|
||||
@ -1544,24 +1550,25 @@ Netrw determines which special handler by the following method:
|
||||
* for Mac OS X : open is used.
|
||||
* for Linux : xdg-open is used.
|
||||
|
||||
To open a file <filepath> by the appropriate handler, type
|
||||
To open a path (or URL) <path> by the appropriate handler, type >
|
||||
|
||||
:Open <filepath>
|
||||
:Open <path>
|
||||
<
|
||||
No escaping, neither for the shell nor for Vim's command-line, is needed.
|
||||
|
||||
No escaping, neither for the shell, nor for Vim's command-line is needed.
|
||||
To launch a specific application <app> <args>, often <args> being <path> >
|
||||
|
||||
To launch a specific application <app> <args>, often <args> being <filepath>,
|
||||
|
||||
:Launch <app> <args>.
|
||||
:Launch <app> <args>.
|
||||
|
||||
Since <args> can be arbitrarily complex, in particular contain many file
|
||||
paths, the escaping is left to the user.
|
||||
|
||||
Associated setting variables:
|
||||
|g:netrw_gx| control how gx picks up the text under the cursor
|
||||
|g:netrw_nogx| prevent gx map while editing
|
||||
|g:netrw_suppress_gx_mesg| controls gx's suppression of browser messages
|
||||
If you disabled the netrw plugin by setting g:loaded_netrwPlugin (see
|
||||
|netrw-noload|), then you can use >
|
||||
|
||||
:call netrw#Launch('<app> <args>')
|
||||
:call netrw#Open('<path>')
|
||||
<
|
||||
*netrw-curdir*
|
||||
DELETING BOOKMARKS *netrw-mB* {{{2
|
||||
|
||||
|
||||
@ -2129,6 +2129,7 @@ $quote eval.txt /*$quote*
|
||||
:LP pi_logipat.txt /*:LP*
|
||||
:LPE pi_logipat.txt /*:LPE*
|
||||
:LPF pi_logipat.txt /*:LPF*
|
||||
:Launch pi_netrw.txt /*:Launch*
|
||||
:Lexplore pi_netrw.txt /*:Lexplore*
|
||||
:Lfilter quickfix.txt /*:Lfilter*
|
||||
:LogiPat pi_logipat.txt /*:LogiPat*
|
||||
@ -2146,6 +2147,7 @@ $quote eval.txt /*$quote*
|
||||
:Ntree pi_netrw.txt /*:Ntree*
|
||||
:Nw pi_netrw.txt /*:Nw*
|
||||
:Nwrite pi_netrw.txt /*:Nwrite*
|
||||
:Open pi_netrw.txt /*:Open*
|
||||
:Over terminal.txt /*:Over*
|
||||
:P various.txt /*:P*
|
||||
:Pexplore pi_netrw.txt /*:Pexplore*
|
||||
@ -5566,7 +5568,6 @@ KeyInputPre autocmd.txt /*KeyInputPre*
|
||||
Kibaale uganda.txt /*Kibaale*
|
||||
Korean mbyte.txt /*Korean*
|
||||
L motion.txt /*L*
|
||||
Launch pi_netrw.txt /*Launch*
|
||||
Linux-backspace options.txt /*Linux-backspace*
|
||||
List eval.txt /*List*
|
||||
Lists eval.txt /*Lists*
|
||||
@ -5622,7 +5623,6 @@ OS390-open-source os_390.txt /*OS390-open-source*
|
||||
Object vim9class.txt /*Object*
|
||||
OffTheSpot mbyte.txt /*OffTheSpot*
|
||||
OnTheSpot mbyte.txt /*OnTheSpot*
|
||||
Open pi_netrw.txt /*Open*
|
||||
Operator-pending intro.txt /*Operator-pending*
|
||||
Operator-pending-mode intro.txt /*Operator-pending-mode*
|
||||
OptionSet autocmd.txt /*OptionSet*
|
||||
|
||||
Reference in New Issue
Block a user