mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 00:52:44 +00:00
vim-patch:8b0fa7a: runtime(netrw): make :Launch/Open autoloadable
fixes: vim/vim#15959
closes: vim/vim#15962
8b0fa7a565
Co-authored-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
This commit is contained in:
@@ -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
|
||||||
@@ -1155,47 +1156,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
|
||||||
@@ -1204,11 +1193,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
|
||||||
@@ -1217,18 +1204,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
|
||||||
@@ -1241,11 +1223,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
|
||||||
@@ -1258,10 +1236,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
|
||||||
|
|
||||||
" ---------------------------------------------------------------------
|
" ---------------------------------------------------------------------
|
||||||
@@ -5217,6 +5193,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.
|
||||||
@@ -5300,31 +5390,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,
|
||||||
@@ -5621,7 +5688,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')
|
||||||
@@ -5635,7 +5702,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
|
||||||
|
|
||||||
@@ -8110,7 +8176,7 @@ fun! netrw#Shrink()
|
|||||||
elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
|
elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
|
||||||
exe "vert resize ".t:netrw_winwidth
|
exe "vert resize ".t:netrw_winwidth
|
||||||
" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
|
" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
|
||||||
else
|
else
|
||||||
call netrw#Lexplore(0,0)
|
call netrw#Lexplore(0,0)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -8427,7 +8493,7 @@ fun! s:NetrwPrevWinOpen(islocal)
|
|||||||
" call Decho("COMBAK#11: mod=".&mod)
|
" call Decho("COMBAK#11: mod=".&mod)
|
||||||
" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
|
" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
|
||||||
" call Decho("COMBAK#12: mod=".&mod)
|
" call Decho("COMBAK#12: mod=".&mod)
|
||||||
|
|
||||||
if exists("s:lexplore_win") && s:lexplore_win == winnr()
|
if exists("s:lexplore_win") && s:lexplore_win == winnr()
|
||||||
" whoops -- user trying to open file in the Lexplore window.
|
" whoops -- user trying to open file in the Lexplore window.
|
||||||
" Use Lexplore's opening-file window instead.
|
" Use Lexplore's opening-file window instead.
|
||||||
@@ -11832,7 +11898,7 @@ fun! s:NetrwEnew(...)
|
|||||||
" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
|
" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
|
||||||
" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
|
" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
|
||||||
|
|
||||||
" Clean out the last buffer:
|
" Clean out the last buffer:
|
||||||
" Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
|
" Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
|
||||||
" If so, delete it.
|
" If so, delete it.
|
||||||
call s:NetrwBufRemover(bufnr("$"))
|
call s:NetrwBufRemover(bufnr("$"))
|
||||||
@@ -12024,7 +12090,7 @@ fun! s:NetrwHumanReadable(sz)
|
|||||||
" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
|
" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
|
||||||
|
|
||||||
if g:netrw_sizestyle == 'h'
|
if g:netrw_sizestyle == 'h'
|
||||||
if a:sz >= 1000000000
|
if a:sz >= 1000000000
|
||||||
let sz = printf("%.1f",a:sz/1000000000.0)."g"
|
let sz = printf("%.1f",a:sz/1000000000.0)."g"
|
||||||
elseif a:sz >= 10000000
|
elseif a:sz >= 10000000
|
||||||
let sz = printf("%d",a:sz/1000000)."m"
|
let sz = printf("%d",a:sz/1000000)."m"
|
||||||
@@ -12452,7 +12518,7 @@ endfun
|
|||||||
fun! s:ShellEscape(s, ...)
|
fun! s:ShellEscape(s, ...)
|
||||||
if has('win32') && $SHELL == '' && &shellslash
|
if has('win32') && $SHELL == '' && &shellslash
|
||||||
return printf('"%s"', substitute(a:s, '"', '""', 'g'))
|
return printf('"%s"', substitute(a:s, '"', '""', 'g'))
|
||||||
endif
|
endif
|
||||||
let f = a:0 > 0 ? a:1 : 0
|
let f = a:0 > 0 ? a:1 : 0
|
||||||
return shellescape(a:s, f)
|
return shellescape(a:s, f)
|
||||||
endfun
|
endfun
|
||||||
|
|||||||
@@ -1465,7 +1465,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
|
||||||
@@ -1475,7 +1474,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
|
||||||
@@ -1486,47 +1485,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:
|
||||||
|
|
||||||
@@ -1540,24 +1546,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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user