mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
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:
parent
9f32069b8c
commit
8b0fa7a565
@ -30,6 +30,7 @@
|
|||||||
" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
|
" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
|
||||||
" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
|
" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
|
||||||
" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
|
" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
|
||||||
|
" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
|
||||||
" }}}
|
" }}}
|
||||||
" Former Maintainer: Charles E Campbell
|
" Former Maintainer: Charles E Campbell
|
||||||
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
|
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
|
||||||
@ -1195,47 +1196,35 @@ fun! netrw#Lexplore(count,rightside,...)
|
|||||||
" if a netrw window is already on the left-side of the tab
|
" if a netrw window is already on the left-side of the tab
|
||||||
" and a directory has been specified, explore with that
|
" and a directory has been specified, explore with that
|
||||||
" directory.
|
" directory.
|
||||||
" call Decho("case has input argument(s) (a:1<".a:1.">)")
|
|
||||||
let a1 = expand(a:1)
|
let a1 = expand(a:1)
|
||||||
" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
|
|
||||||
exe "1wincmd w"
|
exe "1wincmd w"
|
||||||
if &ft == "netrw"
|
if &ft == "netrw"
|
||||||
" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
|
|
||||||
exe "Explore ".fnameescape(a1)
|
exe "Explore ".fnameescape(a1)
|
||||||
exe curwin."wincmd w"
|
exe curwin."wincmd w"
|
||||||
let s:lexplore_win= curwin
|
let s:lexplore_win= curwin
|
||||||
let w:lexplore_buf= bufnr("%")
|
let w:lexplore_buf= bufnr("%")
|
||||||
if exists("t:netrw_lexposn")
|
if exists("t:netrw_lexposn")
|
||||||
" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
|
|
||||||
unlet t:netrw_lexposn
|
unlet t:netrw_lexposn
|
||||||
endif
|
endif
|
||||||
" call Dret("netrw#Lexplore")
|
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
exe curwin."wincmd w"
|
exe curwin."wincmd w"
|
||||||
else
|
else
|
||||||
let a1= ""
|
let a1= ""
|
||||||
" call Decho("no input arguments")
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("t:netrw_lexbufnr")
|
if exists("t:netrw_lexbufnr")
|
||||||
" check if t:netrw_lexbufnr refers to a netrw window
|
" check if t:netrw_lexbufnr refers to a netrw window
|
||||||
let lexwinnr = bufwinnr(t:netrw_lexbufnr)
|
let lexwinnr = bufwinnr(t:netrw_lexbufnr)
|
||||||
" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
|
|
||||||
else
|
else
|
||||||
let lexwinnr= 0
|
let lexwinnr= 0
|
||||||
" call Decho("t:netrw_lexbufnr doesn't exist")
|
|
||||||
endif
|
endif
|
||||||
" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
|
|
||||||
|
|
||||||
if lexwinnr > 0
|
if lexwinnr > 0
|
||||||
" close down netrw explorer window
|
" close down netrw explorer window
|
||||||
" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
|
|
||||||
exe lexwinnr."wincmd w"
|
exe lexwinnr."wincmd w"
|
||||||
let g:netrw_winsize = -winwidth(0)
|
let g:netrw_winsize = -winwidth(0)
|
||||||
let t:netrw_lexposn = winsaveview()
|
let t:netrw_lexposn = winsaveview()
|
||||||
" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
|
|
||||||
" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
|
|
||||||
close
|
close
|
||||||
if lexwinnr < curwin
|
if lexwinnr < curwin
|
||||||
let curwin= curwin - 1
|
let curwin= curwin - 1
|
||||||
@ -1244,11 +1233,9 @@ fun! netrw#Lexplore(count,rightside,...)
|
|||||||
exe curwin."wincmd w"
|
exe curwin."wincmd w"
|
||||||
endif
|
endif
|
||||||
unlet t:netrw_lexbufnr
|
unlet t:netrw_lexbufnr
|
||||||
" call Decho("unlet t:netrw_lexbufnr")
|
|
||||||
|
|
||||||
else
|
else
|
||||||
" open netrw explorer window
|
" open netrw explorer window
|
||||||
" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
|
|
||||||
exe "1wincmd w"
|
exe "1wincmd w"
|
||||||
let keep_altv = g:netrw_altv
|
let keep_altv = g:netrw_altv
|
||||||
let g:netrw_altv = 0
|
let g:netrw_altv = 0
|
||||||
@ -1257,18 +1244,13 @@ fun! netrw#Lexplore(count,rightside,...)
|
|||||||
let g:netrw_winsize = a:count
|
let g:netrw_winsize = a:count
|
||||||
endif
|
endif
|
||||||
let curfile= expand("%")
|
let curfile= expand("%")
|
||||||
" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
|
|
||||||
exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
|
exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
|
||||||
" call Decho("new buf#".bufnr("%")." win#".winnr())
|
|
||||||
if a:0 > 0 && a1 != ""
|
if a:0 > 0 && a1 != ""
|
||||||
" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
|
|
||||||
call netrw#Explore(0,0,0,a1)
|
call netrw#Explore(0,0,0,a1)
|
||||||
exe "Explore ".fnameescape(a1)
|
exe "Explore ".fnameescape(a1)
|
||||||
elseif curfile =~ '^\a\{3,}://'
|
elseif curfile =~ '^\a\{3,}://'
|
||||||
" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
|
|
||||||
call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
|
call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
|
||||||
else
|
else
|
||||||
" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
|
|
||||||
call netrw#Explore(0,0,0,".")
|
call netrw#Explore(0,0,0,".")
|
||||||
endif
|
endif
|
||||||
if a:count != 0
|
if a:count != 0
|
||||||
@ -1281,11 +1263,7 @@ fun! netrw#Lexplore(count,rightside,...)
|
|||||||
" Since the intended use of :Lexplore is to have an always-present explorer window, the extra
|
" Since the intended use of :Lexplore is to have an always-present explorer window, the extra
|
||||||
" effort to prevent mis-use of :Lex is warranted.
|
" effort to prevent mis-use of :Lex is warranted.
|
||||||
set bh=wipe
|
set bh=wipe
|
||||||
" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
|
|
||||||
" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
|
|
||||||
if exists("t:netrw_lexposn")
|
if exists("t:netrw_lexposn")
|
||||||
" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
|
|
||||||
" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
|
|
||||||
call winrestview(t:netrw_lexposn)
|
call winrestview(t:netrw_lexposn)
|
||||||
unlet t:netrw_lexposn
|
unlet t:netrw_lexposn
|
||||||
endif
|
endif
|
||||||
@ -1298,10 +1276,8 @@ fun! netrw#Lexplore(count,rightside,...)
|
|||||||
else
|
else
|
||||||
let g:netrw_chgwin= 2
|
let g:netrw_chgwin= 2
|
||||||
endif
|
endif
|
||||||
" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" call Dret("netrw#Lexplore")
|
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
" ---------------------------------------------------------------------
|
" ---------------------------------------------------------------------
|
||||||
@ -5266,6 +5242,120 @@ fun! s:NetrwBrowseUpDir(islocal)
|
|||||||
" call Dret("s:NetrwBrowseUpDir")
|
" call Dret("s:NetrwBrowseUpDir")
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
func s:redir()
|
||||||
|
" set up redirection (avoids browser messages)
|
||||||
|
" by default if not set, g:netrw_suppress_gx_mesg is true
|
||||||
|
if get(g:, 'netrw_suppress_gx_mesg', 1)
|
||||||
|
if &srr =~# "%s"
|
||||||
|
return printf(&srr, has("win32") ? "nul" : "/dev/null")
|
||||||
|
else
|
||||||
|
return &srr .. (has("win32") ? "nul" : "/dev/null")
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return ''
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
if has('unix')
|
||||||
|
if has('win32unix')
|
||||||
|
" Cygwin provides cygstart
|
||||||
|
if executable('cygstart')
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
|
||||||
|
endfun
|
||||||
|
elseif !empty($MSYSTEM) && executable('start')
|
||||||
|
" MSYS2/Git Bash comes by default without cygstart; see
|
||||||
|
" https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
|
||||||
|
" Instead it provides /usr/bin/start script running `cmd.exe //c start`
|
||||||
|
" Adding "" //b` sets void title, hides cmd window and blocks path conversion
|
||||||
|
" of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
exe 'silent !start "" //b' a:args s:redir() | redraw!
|
||||||
|
endfun
|
||||||
|
else
|
||||||
|
" imitate /usr/bin/start script for other environments and hope for the best
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
|
||||||
|
endfun
|
||||||
|
endif
|
||||||
|
elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
let args = a:args
|
||||||
|
exe 'silent !' ..
|
||||||
|
\ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
|
||||||
|
\ 'cmd.exe /c start "" /b ' .. args :
|
||||||
|
\ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
|
||||||
|
\ | redraw!
|
||||||
|
endfun
|
||||||
|
else
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
exe ':silent ! nohup' a:args s:redir() '&' | redraw!
|
||||||
|
endfun
|
||||||
|
endif
|
||||||
|
elseif has('win32')
|
||||||
|
fun! netrw#Launch(args)
|
||||||
|
exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
|
||||||
|
\ 'start "" /b' a:args s:redir() | redraw!
|
||||||
|
endfun
|
||||||
|
else
|
||||||
|
fun! netrw#Launch(dummy)
|
||||||
|
echom 'No common launcher found'
|
||||||
|
endfun
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Git Bash
|
||||||
|
if has('win32unix')
|
||||||
|
" (cyg)start suffices
|
||||||
|
let s:os_viewer = ''
|
||||||
|
" Windows / WSL
|
||||||
|
elseif executable('explorer.exe')
|
||||||
|
let s:os_viewer = 'explorer.exe'
|
||||||
|
" Linux / BSD
|
||||||
|
elseif executable('xdg-open')
|
||||||
|
let s:os_viewer = 'xdg-open'
|
||||||
|
" MacOS
|
||||||
|
elseif executable('open')
|
||||||
|
let s:os_viewer = 'open'
|
||||||
|
endif
|
||||||
|
|
||||||
|
fun! s:viewer()
|
||||||
|
if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
|
||||||
|
" extract any viewing options. Assumes that they're set apart by spaces.
|
||||||
|
" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
|
||||||
|
if g:netrw_browsex_viewer =~ '\s'
|
||||||
|
let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
|
||||||
|
let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
|
||||||
|
let oviewer = ''
|
||||||
|
let cnt = 1
|
||||||
|
while !executable(viewer) && viewer != oviewer
|
||||||
|
let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
|
||||||
|
let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
|
||||||
|
let cnt = cnt + 1
|
||||||
|
let oviewer = viewer
|
||||||
|
" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
|
||||||
|
endwhile
|
||||||
|
else
|
||||||
|
let viewer = g:netrw_browsex_viewer
|
||||||
|
let viewopt = ""
|
||||||
|
endif
|
||||||
|
" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
|
||||||
|
return viewer .. ' ' .. viewopt
|
||||||
|
else
|
||||||
|
if !exists('s:os_viewer')
|
||||||
|
call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
|
||||||
|
else
|
||||||
|
return s:os_viewer
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fun! netrw#Open(file) abort
|
||||||
|
call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
|
||||||
|
endf
|
||||||
|
|
||||||
|
if !exists('g:netrw_regex_url')
|
||||||
|
let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
|
||||||
|
endif
|
||||||
|
|
||||||
" ---------------------------------------------------------------------
|
" ---------------------------------------------------------------------
|
||||||
" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
|
" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
|
||||||
" given filename; typically this means given their extension.
|
" given filename; typically this means given their extension.
|
||||||
@ -5349,31 +5439,8 @@ fun! netrw#BrowseX(fname,remote)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" extract any viewing options. Assumes that they're set apart by spaces.
|
" although shellescape(..., 1) is used in netrw#Open(), it's insufficient
|
||||||
if exists("g:netrw_browsex_viewer")
|
call netrw#Open(escape(fname, '#%'))
|
||||||
if g:netrw_browsex_viewer =~ '\s'
|
|
||||||
let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
|
|
||||||
let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
|
|
||||||
let oviewer = ''
|
|
||||||
let cnt = 1
|
|
||||||
while !executable(viewer) && viewer != oviewer
|
|
||||||
let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
|
|
||||||
let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
|
|
||||||
let cnt = cnt + 1
|
|
||||||
let oviewer = viewer
|
|
||||||
endwhile
|
|
||||||
else
|
|
||||||
let viewer = g:netrw_browsex_viewer
|
|
||||||
let viewopt = ""
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if exists("g:netrw_browsex_viewer") && executable(viewer)
|
|
||||||
exe 'Launch' viewer viewopt shellescape(fname, 1)
|
|
||||||
else
|
|
||||||
" though shellescape(..., 1) is used in Open, it's insufficient
|
|
||||||
exe 'Open' escape(fname, '#%')
|
|
||||||
endif
|
|
||||||
|
|
||||||
" cleanup: remove temporary file,
|
" cleanup: remove temporary file,
|
||||||
" delete current buffer if success with handler,
|
" delete current buffer if success with handler,
|
||||||
@ -5665,7 +5732,7 @@ fun! s:NetrwGlob(direntry,expr,pare)
|
|||||||
endif
|
endif
|
||||||
let w:netrw_liststyle= keep_liststyle
|
let w:netrw_liststyle= keep_liststyle
|
||||||
else
|
else
|
||||||
let path= s:ComposePath(fnameescape(a:direntry),a:expr)
|
let path= s:ComposePath(fnameescape(a:direntry), a:expr)
|
||||||
if has("win32")
|
if has("win32")
|
||||||
" escape [ so it is not detected as wildcard character, see :h wildcard
|
" escape [ so it is not detected as wildcard character, see :h wildcard
|
||||||
let path= substitute(path, '[', '[[]', 'g')
|
let path= substitute(path, '[', '[[]', 'g')
|
||||||
@ -5679,7 +5746,6 @@ fun! s:NetrwGlob(direntry,expr,pare)
|
|||||||
let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
|
let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
" call Dret("s:NetrwGlob ".string(filelist))
|
|
||||||
return filelist
|
return filelist
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
@ -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
|
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
|
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.
|
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
|
CUSTOMIZING BROWSING WITH A SPECIAL HANDLER *netrw-x* *netrw-handler* {{{2
|
||||||
|
|
||||||
Certain files, such as html, gif, jpeg, (word/office) doc, etc, files, are
|
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
|
* hitting gx with the cursor atop the file path or alternatively x
|
||||||
in a netrw buffer; the former can be disabled by defining the
|
in a netrw buffer; the former can be disabled by defining the
|
||||||
|g:netrw_nogx| variable
|
|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
|
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
|
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.
|
|visual-block|) and then pressing gx.
|
||||||
|
|
||||||
The selection function can be adapted for each filetype by adding a function
|
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
|
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.
|
fall back to the default behavior if it returns an empty string.
|
||||||
For example, special handlers for links Markdown and HTML are
|
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()
|
" make gx work on concealed links regardless of exact cursor position: >
|
||||||
" HTML URL such as <a href='http://www.python.org'>Python is here</a>
|
|
||||||
" <a href="http://www.python.org"/>
|
function Netrw_get_URL_markdown()
|
||||||
try
|
" markdown URL such as [link text](http://ya.ru 'yandex search')
|
||||||
let save_view = winsaveview()
|
try
|
||||||
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
|
let save_view = winsaveview()
|
||||||
return matchstr(getline('.')[col('.') - 1 : ],
|
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
|
||||||
\ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
|
return matchstr(getline('.')[col('.')-1:],
|
||||||
endif
|
\ '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
|
||||||
finally
|
endif
|
||||||
call winrestview(save_view)
|
finally
|
||||||
return ''
|
call winrestview(save_view)
|
||||||
endtry
|
return ''
|
||||||
endfunction
|
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
|
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
|
by default the following regular expression to determine if the text under the
|
||||||
cursor is a URL:
|
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:
|
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 Mac OS X : open is used.
|
||||||
* for Linux : xdg-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
|
Since <args> can be arbitrarily complex, in particular contain many file
|
||||||
paths, the escaping is left to the user.
|
paths, the escaping is left to the user.
|
||||||
|
|
||||||
Associated setting variables:
|
If you disabled the netrw plugin by setting g:loaded_netrwPlugin (see
|
||||||
|g:netrw_gx| control how gx picks up the text under the cursor
|
|netrw-noload|), then you can use >
|
||||||
|g:netrw_nogx| prevent gx map while editing
|
|
||||||
|g:netrw_suppress_gx_mesg| controls gx's suppression of browser messages
|
|
||||||
|
|
||||||
|
:call netrw#Launch('<app> <args>')
|
||||||
|
:call netrw#Open('<path>')
|
||||||
|
<
|
||||||
*netrw-curdir*
|
*netrw-curdir*
|
||||||
DELETING BOOKMARKS *netrw-mB* {{{2
|
DELETING BOOKMARKS *netrw-mB* {{{2
|
||||||
|
|
||||||
|
@ -2129,6 +2129,7 @@ $quote eval.txt /*$quote*
|
|||||||
:LP pi_logipat.txt /*:LP*
|
:LP pi_logipat.txt /*:LP*
|
||||||
:LPE pi_logipat.txt /*:LPE*
|
:LPE pi_logipat.txt /*:LPE*
|
||||||
:LPF pi_logipat.txt /*:LPF*
|
:LPF pi_logipat.txt /*:LPF*
|
||||||
|
:Launch pi_netrw.txt /*:Launch*
|
||||||
:Lexplore pi_netrw.txt /*:Lexplore*
|
:Lexplore pi_netrw.txt /*:Lexplore*
|
||||||
:Lfilter quickfix.txt /*:Lfilter*
|
:Lfilter quickfix.txt /*:Lfilter*
|
||||||
:LogiPat pi_logipat.txt /*:LogiPat*
|
:LogiPat pi_logipat.txt /*:LogiPat*
|
||||||
@ -2146,6 +2147,7 @@ $quote eval.txt /*$quote*
|
|||||||
:Ntree pi_netrw.txt /*:Ntree*
|
:Ntree pi_netrw.txt /*:Ntree*
|
||||||
:Nw pi_netrw.txt /*:Nw*
|
:Nw pi_netrw.txt /*:Nw*
|
||||||
:Nwrite pi_netrw.txt /*:Nwrite*
|
:Nwrite pi_netrw.txt /*:Nwrite*
|
||||||
|
:Open pi_netrw.txt /*:Open*
|
||||||
:Over terminal.txt /*:Over*
|
:Over terminal.txt /*:Over*
|
||||||
:P various.txt /*:P*
|
:P various.txt /*:P*
|
||||||
:Pexplore pi_netrw.txt /*:Pexplore*
|
:Pexplore pi_netrw.txt /*:Pexplore*
|
||||||
@ -5566,7 +5568,6 @@ KeyInputPre autocmd.txt /*KeyInputPre*
|
|||||||
Kibaale uganda.txt /*Kibaale*
|
Kibaale uganda.txt /*Kibaale*
|
||||||
Korean mbyte.txt /*Korean*
|
Korean mbyte.txt /*Korean*
|
||||||
L motion.txt /*L*
|
L motion.txt /*L*
|
||||||
Launch pi_netrw.txt /*Launch*
|
|
||||||
Linux-backspace options.txt /*Linux-backspace*
|
Linux-backspace options.txt /*Linux-backspace*
|
||||||
List eval.txt /*List*
|
List eval.txt /*List*
|
||||||
Lists eval.txt /*Lists*
|
Lists eval.txt /*Lists*
|
||||||
@ -5622,7 +5623,6 @@ OS390-open-source os_390.txt /*OS390-open-source*
|
|||||||
Object vim9class.txt /*Object*
|
Object vim9class.txt /*Object*
|
||||||
OffTheSpot mbyte.txt /*OffTheSpot*
|
OffTheSpot mbyte.txt /*OffTheSpot*
|
||||||
OnTheSpot mbyte.txt /*OnTheSpot*
|
OnTheSpot mbyte.txt /*OnTheSpot*
|
||||||
Open pi_netrw.txt /*Open*
|
|
||||||
Operator-pending intro.txt /*Operator-pending*
|
Operator-pending intro.txt /*Operator-pending*
|
||||||
Operator-pending-mode intro.txt /*Operator-pending-mode*
|
Operator-pending-mode intro.txt /*Operator-pending-mode*
|
||||||
OptionSet autocmd.txt /*OptionSet*
|
OptionSet autocmd.txt /*OptionSet*
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
|
" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
|
||||||
" 2024 Oct 27 by Vim Project: cleanup gx mapping
|
" 2024 Oct 27 by Vim Project: cleanup gx mapping
|
||||||
" 2024 Oct 28 by Vim Project: further improvements
|
" 2024 Oct 28 by Vim Project: further improvements
|
||||||
|
" 2024 Oct 31 by Vim Project: use autoloaded functions
|
||||||
" Former Maintainer: Charles E Campbell
|
" Former Maintainer: Charles E Campbell
|
||||||
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
|
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
|
||||||
" Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1
|
" Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1
|
||||||
@ -34,84 +35,8 @@ set cpo&vim
|
|||||||
" Public Interface: {{{1
|
" Public Interface: {{{1
|
||||||
|
|
||||||
" Commands Launch/URL {{{2
|
" Commands Launch/URL {{{2
|
||||||
" surpress output of command; use bang for GUI applications
|
command -complete=shellcmd -nargs=1 Launch call netrw#Launch(trim(<q-args>))
|
||||||
|
command -complete=file -nargs=1 Open call netrw#Open(trim(<q-args>))
|
||||||
func s:redir()
|
|
||||||
" set up redirection (avoids browser messages)
|
|
||||||
" by default if not set, g:netrw_suppress_gx_mesg is true
|
|
||||||
if get(g:, 'netrw_suppress_gx_mesg', 1)
|
|
||||||
if &srr =~# "%s"
|
|
||||||
return printf(&srr, has("win32") ? "nul" : "/dev/null")
|
|
||||||
else
|
|
||||||
return &srr .. (has("win32") ? "nul" : "/dev/null")
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return ''
|
|
||||||
endfunc
|
|
||||||
|
|
||||||
if has('unix')
|
|
||||||
if has('win32unix')
|
|
||||||
" If cygstart provided, then assume Cygwin and use cygstart --hide; see man cygstart.
|
|
||||||
if executable('cygstart')
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch
|
|
||||||
\ exe 'silent ! cygstart --hide' trim(<q-args>) s:redir() | redraw!
|
|
||||||
elseif !empty($MSYSTEM) && executable('start')
|
|
||||||
" MSYS2/Git Bash comes by default without cygstart; see
|
|
||||||
" https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
|
|
||||||
" Instead it provides /usr/bin/start script running `cmd.exe //c start`
|
|
||||||
" Adding "" //b` sets void title, hides cmd window and blocks path conversion
|
|
||||||
" of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch
|
|
||||||
\ exe 'silent !start "" //b' trim(<q-args>) s:redir() | redraw!
|
|
||||||
else
|
|
||||||
" imitate /usr/bin/start script for other environments and hope for the best
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch
|
|
||||||
\ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir() | redraw!
|
|
||||||
endif
|
|
||||||
elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'..
|
|
||||||
\ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
|
|
||||||
\ 'cmd.exe /c start "" /b' trim(<q-args>) :
|
|
||||||
\ 'nohup ' trim(<q-args>) s:redir() '&')
|
|
||||||
\ | redraw!
|
|
||||||
else
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch
|
|
||||||
\ exe ':silent ! nohup' trim(<q-args>) s:redir() '&' | redraw!
|
|
||||||
endif
|
|
||||||
elseif has('win32')
|
|
||||||
command -complete=shellcmd -nargs=1 -bang Launch
|
|
||||||
\ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
|
|
||||||
\ 'start /b ' trim(<q-args>) s:redir() | redraw!
|
|
||||||
endif
|
|
||||||
if exists(':Launch') == 2
|
|
||||||
" Git Bash
|
|
||||||
if has('win32unix')
|
|
||||||
" start suffices
|
|
||||||
let s:cmd = ''
|
|
||||||
" Windows / WSL
|
|
||||||
elseif executable('explorer.exe')
|
|
||||||
let s:cmd = 'explorer.exe'
|
|
||||||
" Linux / BSD
|
|
||||||
elseif executable('xdg-open')
|
|
||||||
let s:cmd = 'xdg-open'
|
|
||||||
" MacOS
|
|
||||||
elseif executable('open')
|
|
||||||
let s:cmd = 'open'
|
|
||||||
endif
|
|
||||||
function s:Open(file)
|
|
||||||
if !exists('s:cmd') && !exists('g:netrw_browsex_viewer')
|
|
||||||
echoerr "No program to open this path found. See :help Open for more information."
|
|
||||||
else
|
|
||||||
exe 'Launch' s:cmd shellescape(a:file, 1)
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
command -complete=file -nargs=1 Open call s:Open(<q-args>)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !exists('g:netrw_regex_url')
|
|
||||||
let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
|
|
||||||
endif
|
|
||||||
|
|
||||||
" " }}}
|
" " }}}
|
||||||
" Local Browsing Autocmds: {{{2
|
" Local Browsing Autocmds: {{{2
|
||||||
augroup FileExplorer
|
augroup FileExplorer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user