aboutsummaryrefslogtreecommitdiff
path: root/runtime/plugin/netrwPlugin.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/plugin/netrwPlugin.vim')
-rw-r--r--runtime/plugin/netrwPlugin.vim84
1 files changed, 83 insertions, 1 deletions
diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim
index c70e6518ff..59fb7e727e 100644
--- a/runtime/plugin/netrwPlugin.vim
+++ b/runtime/plugin/netrwPlugin.vim
@@ -1,9 +1,10 @@
" netrwPlugin.vim: Handles file transfer and remote directory listing across a network
" PLUGIN SECTION
" Maintainer: This runtime file is looking for a new maintainer.
-" Date: Feb 09, 2021
+" Date: Sep 09, 2021
" Last Change:
" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
+" 2024 Oct 27 by Vim Project: cleanup gx mapping
" Former Maintainer: Charles E Campbell
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
" Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1
@@ -31,6 +32,87 @@ set cpo&vim
" ---------------------------------------------------------------------
" Public Interface: {{{1
+" Commands Launch/URL {{{2
+" surpress output of command; use bang for GUI applications
+
+" set up redirection (avoids browser messages)
+" by default, g:netrw_suppress_gx_mesg is true
+if get(g:, ':netrw_suppress_gx_mesg', 1)
+ if &srr =~# "%s"
+ let s:redir = printf(&srr, has("win32") ? "nul" : "/dev/null")
+ else
+ let s:redir= &srr .. (has("win32") ? "nul" : "/dev/null")
+ endif
+else
+ let s:redir= ""
+endif
+
+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'
+ else
+ s:cmd = ''
+ endif
+ function s:Open(cmd, file)
+ if empty(a:cmd) && !exists('g:netrw_browsex_viewer')
+ echoerr "No program to open this path found. See :help Open for more information."
+ else
+ Launch cmd shellescape(a:file, 1)
+ endif
+ endfunction
+ command -complete=file -nargs=1 Open call s:Open(s:cmd, <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
augroup FileExplorer
au!