Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 1 | " netrwPlugin.vim: Handles file transfer and remote directory listing across a network |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 2 | " PLUGIN SECTION |
Christian Brabandt | f9ca139 | 2024-02-19 20:37:11 +0100 | [diff] [blame] | 3 | " Maintainer: This runtime file is looking for a new maintainer. |
Konfekt | 3d7e567 | 2024-10-27 22:16:49 +0100 | [diff] [blame^] | 4 | " Date: Sep 09, 2021 |
Nir Lichtman | 1e34b95 | 2024-05-08 19:19:34 +0200 | [diff] [blame] | 5 | " Last Change: |
| 6 | " 2024 May 08 by Vim Project: cleanup legacy Win9X checks |
Konfekt | 3d7e567 | 2024-10-27 22:16:49 +0100 | [diff] [blame^] | 7 | " 2024 Oct 27 by Vim Project: cleanup gx mapping |
Christian Brabandt | f9ca139 | 2024-02-19 20:37:11 +0100 | [diff] [blame] | 8 | " Former Maintainer: Charles E Campbell |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 9 | " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 10 | " Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1 |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 11 | " Permission is hereby granted to use and distribute this code, |
| 12 | " with or without modifications, provided that this copyright |
| 13 | " notice is copied with it. Like anything else that's free, |
| 14 | " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided |
| 15 | " *as is* and comes with no warranty of any kind, either |
| 16 | " expressed or implied. By using this plugin, you agree that |
| 17 | " in no event will the copyright holder be liable for any damages |
| 18 | " resulting from the use of this software. |
| 19 | " |
| 20 | " But be doers of the Word, and not only hearers, deluding your own selves {{{1 |
| 21 | " (James 1:22 RSV) |
| 22 | " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 23 | " Load Once: {{{1 |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 24 | if &cp || exists("g:loaded_netrwPlugin") |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 25 | finish |
| 26 | endif |
Bram Moolenaar | b7398fe | 2023-05-14 18:50:25 +0100 | [diff] [blame] | 27 | let g:loaded_netrwPlugin = "v173" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 28 | let s:keepcpo = &cpo |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 29 | set cpo&vim |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 30 | "DechoRemOn |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 31 | |
| 32 | " --------------------------------------------------------------------- |
| 33 | " Public Interface: {{{1 |
| 34 | |
Konfekt | 3d7e567 | 2024-10-27 22:16:49 +0100 | [diff] [blame^] | 35 | " Commands Launch/URL {{{2 |
| 36 | " surpress output of command; use bang for GUI applications |
| 37 | |
| 38 | " set up redirection (avoids browser messages) |
| 39 | " by default, g:netrw_suppress_gx_mesg is true |
| 40 | if get(g:, ':netrw_suppress_gx_mesg', 1) |
| 41 | if &srr =~# "%s" |
| 42 | let s:redir = printf(&srr, has("win32") ? "nul" : "/dev/null") |
| 43 | else |
| 44 | let s:redir= &srr .. (has("win32") ? "nul" : "/dev/null") |
| 45 | endif |
| 46 | else |
| 47 | let s:redir= "" |
| 48 | endif |
| 49 | |
| 50 | if has('unix') |
| 51 | if has('win32unix') |
| 52 | " If cygstart provided, then assume Cygwin and use cygstart --hide; see man cygstart. |
| 53 | if executable('cygstart') |
| 54 | command -complete=shellcmd -nargs=1 -bang Launch |
| 55 | \ exe 'silent ! cygstart --hide' trim(<q-args>) s:redir | redraw! |
| 56 | elseif !empty($MSYSTEM) && executable('start') |
| 57 | " MSYS2/Git Bash comes by default without cygstart; see |
| 58 | " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin |
| 59 | " Instead it provides /usr/bin/start script running `cmd.exe //c start` |
| 60 | " Adding "" //b` sets void title, hides cmd window and blocks path conversion |
| 61 | " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/ |
| 62 | command -complete=shellcmd -nargs=1 -bang Launch |
| 63 | \ exe 'silent !start "" //b' trim(<q-args>) s:redir | redraw! |
| 64 | else |
| 65 | " imitate /usr/bin/start script for other environments and hope for the best |
| 66 | command -complete=shellcmd -nargs=1 -bang Launch |
| 67 | \ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir | redraw! |
| 68 | endif |
| 69 | elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL |
| 70 | command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'.. |
| 71 | \ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ? |
| 72 | \ 'cmd.exe /c start "" /b' trim(<q-args>) : |
| 73 | \ 'nohup ' trim(<q-args>) s:redir '&') |
| 74 | \ | redraw! |
| 75 | else |
| 76 | command -complete=shellcmd -nargs=1 -bang Launch |
| 77 | \ exe ':silent ! nohup' trim(<q-args>) s:redir '&' | redraw! |
| 78 | endif |
| 79 | elseif has('win32') |
| 80 | command -complete=shellcmd -nargs=1 -bang Launch |
| 81 | \ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c') |
| 82 | \ 'start /b ' trim(<q-args>) s:redir | redraw! |
| 83 | endif |
| 84 | if exists(':Launch') == 2 |
| 85 | " Git Bash |
| 86 | if has('win32unix') |
| 87 | " start suffices |
| 88 | let s:cmd = '' |
| 89 | " Windows / WSL |
| 90 | elseif executable('explorer.exe') |
| 91 | let s:cmd = 'explorer.exe' |
| 92 | " Linux / BSD |
| 93 | elseif executable('xdg-open') |
| 94 | let s:cmd = 'xdg-open' |
| 95 | " MacOS |
| 96 | elseif executable('open') |
| 97 | let s:cmd = 'open' |
| 98 | else |
| 99 | s:cmd = '' |
| 100 | endif |
| 101 | function s:Open(cmd, file) |
| 102 | if empty(a:cmd) && !exists('g:netrw_browsex_viewer') |
| 103 | echoerr "No program to open this path found. See :help Open for more information." |
| 104 | else |
| 105 | Launch cmd shellescape(a:file, 1) |
| 106 | endif |
| 107 | endfunction |
| 108 | command -complete=file -nargs=1 Open call s:Open(s:cmd, <q-args>) |
| 109 | endif |
| 110 | |
| 111 | if !exists('g:netrw_regex_url') |
| 112 | let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}' |
| 113 | endif |
| 114 | |
| 115 | " " }}} |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 116 | " Local Browsing Autocmds: {{{2 |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 117 | augroup FileExplorer |
| 118 | au! |
Bram Moolenaar | a687837 | 2014-03-22 21:02:50 +0100 | [diff] [blame] | 119 | au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 120 | au BufEnter * sil call s:LocalBrowse(expand("<amatch>")) |
| 121 | au VimEnter * sil call s:VimEnter(expand("<amatch>")) |
Nir Lichtman | 1e34b95 | 2024-05-08 19:19:34 +0200 | [diff] [blame] | 122 | if has("win32") |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 123 | au BufEnter .* sil call s:LocalBrowse(expand("<amatch>")) |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 124 | endif |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 125 | augroup END |
| 126 | |
| 127 | " Network Browsing Reading Writing: {{{2 |
| 128 | augroup Network |
| 129 | au! |
Bram Moolenaar | 85850f3 | 2019-07-19 22:05:51 +0200 | [diff] [blame] | 130 | au BufReadCmd file://* call netrw#FileUrlEdit(expand("<amatch>")) |
| 131 | au BufReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "sil doau BufReadPost ".fnameescape(expand("<amatch>")) |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 132 | au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(1,expand("<amatch>"))|exe "sil doau FileReadPost ".fnameescape(expand("<amatch>")) |
| 133 | au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau BufWritePost ".fnameescape(expand("<amatch>")) |
| 134 | au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau FileWritePost ".fnameescape(expand("<amatch>")) |
Bram Moolenaar | 589edb3 | 2019-09-20 14:38:13 +0200 | [diff] [blame] | 135 | try |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 136 | au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) |
Bram Moolenaar | 589edb3 | 2019-09-20 14:38:13 +0200 | [diff] [blame] | 137 | catch /^Vim\%((\a\+)\)\=:E216/ |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 138 | au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 139 | endtry |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 140 | augroup END |
| 141 | |
| 142 | " Commands: :Nread, :Nwrite, :NetUserPass {{{2 |
Bram Moolenaar | e0fa374 | 2016-02-20 15:47:01 +0100 | [diff] [blame] | 143 | com! -count=1 -nargs=* Nread let s:svpos= winsaveview()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call winrestview(s:svpos) |
| 144 | com! -range=% -nargs=* Nwrite let s:svpos= winsaveview()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call winrestview(s:svpos) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 145 | com! -nargs=* NetUserPass call NetUserPass(<f-args>) |
Bram Moolenaar | e0fa374 | 2016-02-20 15:47:01 +0100 | [diff] [blame] | 146 | com! -nargs=* Nsource let s:svpos= winsaveview()<bar>call netrw#NetSource(<f-args>)<bar>call winrestview(s:svpos) |
Bram Moolenaar | 85850f3 | 2019-07-19 22:05:51 +0200 | [diff] [blame] | 147 | com! -nargs=? Ntree call netrw#SetTreetop(1,<q-args>) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 148 | |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 149 | " Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2 |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 150 | com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>) |
| 151 | com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>) |
| 152 | com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>) |
| 153 | com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>) |
| 154 | com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>) |
| 155 | com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>) |
| 156 | com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>) |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 157 | com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(<count>,<bang>0,<q-args>) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 158 | |
| 159 | " Commands: NetrwSettings {{{2 |
Bram Moolenaar | f233048 | 2008-06-24 20:19:36 +0000 | [diff] [blame] | 160 | com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() |
Bram Moolenaar | a687837 | 2014-03-22 21:02:50 +0100 | [diff] [blame] | 161 | com! -bang NetrwClean call netrw#Clean(<bang>0) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 162 | |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 163 | " Maps: |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 164 | if !exists("g:netrw_nogx") |
| 165 | if maparg('gx','n') == "" |
| 166 | if !hasmapto('<Plug>NetrwBrowseX') |
| 167 | nmap <unique> gx <Plug>NetrwBrowseX |
| 168 | endif |
Bram Moolenaar | 5ef1c6a | 2019-11-10 22:09:11 +0100 | [diff] [blame] | 169 | nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))<cr> |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 170 | endif |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 171 | if maparg('gx','x') == "" |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 172 | if !hasmapto('<Plug>NetrwBrowseXVis') |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 173 | xmap <unique> gx <Plug>NetrwBrowseXVis |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 174 | endif |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 175 | xno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr> |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 176 | endif |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 177 | endif |
Bram Moolenaar | a0f849e | 2015-10-30 14:37:44 +0100 | [diff] [blame] | 178 | if exists("g:netrw_usetab") && g:netrw_usetab |
| 179 | if maparg('<c-tab>','n') == "" |
| 180 | nmap <unique> <c-tab> <Plug>NetrwShrink |
| 181 | endif |
| 182 | nno <silent> <Plug>NetrwShrink :call netrw#Shrink()<cr> |
| 183 | endif |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 184 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 185 | " --------------------------------------------------------------------- |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 186 | " LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2 |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 187 | fun! s:LocalBrowse(dirname) |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 188 | " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here. |
| 189 | " Otherwise, the BufEnter event gets triggered when attempts to write to |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 190 | " the DBG buffer are made. |
Bram Moolenaar | 589edb3 | 2019-09-20 14:38:13 +0200 | [diff] [blame] | 191 | |
Bram Moolenaar | e6ae622 | 2013-05-21 21:01:10 +0200 | [diff] [blame] | 192 | if !exists("s:vimentered") |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 193 | " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, |
| 194 | " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. |
| 195 | " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") |
| 196 | " call Dret("s:LocalBrowse") |
Bram Moolenaar | e6ae622 | 2013-05-21 21:01:10 +0200 | [diff] [blame] | 197 | return |
| 198 | endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 199 | |
| 200 | " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") |
| 201 | |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 202 | if has("amiga") |
| 203 | " The check against '' is made for the Amiga, where the empty |
| 204 | " string is the current directory and not checking would break |
| 205 | " things such as the help command. |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 206 | " call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 207 | if a:dirname != '' && isdirectory(a:dirname) |
Bram Moolenaar | adc2182 | 2011-04-01 18:03:16 +0200 | [diff] [blame] | 208 | sil! call netrw#LocalBrowseCheck(a:dirname) |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 209 | if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt |
Bram Moolenaar | a687837 | 2014-03-22 21:02:50 +0100 | [diff] [blame] | 210 | exe w:netrw_bannercnt |
| 211 | endif |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 212 | endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 213 | |
Bram Moolenaar | dd2a3cd | 2007-05-05 17:10:09 +0000 | [diff] [blame] | 214 | elseif isdirectory(a:dirname) |
Bram Moolenaar | a687837 | 2014-03-22 21:02:50 +0100 | [diff] [blame] | 215 | " call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)") |
| 216 | " call Dredir("LocalBrowse ft last set: ","verbose set ft") |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 217 | " Jul 13, 2021: for whatever reason, preceding the following call with |
| 218 | " a sil! causes an unbalanced if-endif vim error |
| 219 | call netrw#LocalBrowseCheck(a:dirname) |
Bram Moolenaar | 8feef4f | 2015-01-07 16:57:10 +0100 | [diff] [blame] | 220 | if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt |
Bram Moolenaar | a687837 | 2014-03-22 21:02:50 +0100 | [diff] [blame] | 221 | exe w:netrw_bannercnt |
| 222 | endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 223 | |
| 224 | else |
| 225 | " not a directory, ignore it |
| 226 | " call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 227 | endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 228 | |
| 229 | " call Dret("s:LocalBrowse") |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 230 | endfun |
| 231 | |
| 232 | " --------------------------------------------------------------------- |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 233 | " s:VimEnter: after all vim startup stuff is done, this function is called. {{{2 |
| 234 | " Its purpose: to look over all windows and run s:LocalBrowse() on |
| 235 | " them, which checks if they're directories and will create a directory |
| 236 | " listing when appropriate. |
| 237 | " It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() |
| 238 | " has already been called. |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 239 | fun! s:VimEnter(dirname) |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 240 | " call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 241 | if has('nvim') || v:version < 802 |
| 242 | " Johann Hรถchtl: reported that the call range... line causes an E488: Trailing characters |
| 243 | " error with neovim. I suspect its because neovim hasn't updated with recent |
| 244 | " vim patches. As is, this code will have problems with popup terminals |
| 245 | " instantiated before the VimEnter event runs. |
| 246 | " Ingo Karkat : E488 also in Vim 8.1.1602 |
Bram Moolenaar | e6ae622 | 2013-05-21 21:01:10 +0200 | [diff] [blame] | 247 | let curwin = winnr() |
| 248 | let s:vimentered = 1 |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 249 | windo call s:LocalBrowse(expand("%:p")) |
Bram Moolenaar | 477db06 | 2010-07-28 18:17:41 +0200 | [diff] [blame] | 250 | exe curwin."wincmd w" |
Bram Moolenaar | 89a9c15 | 2021-08-29 21:55:35 +0200 | [diff] [blame] | 251 | else |
| 252 | " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and |
| 253 | " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. |
| 254 | let s:vimentered = 1 |
| 255 | call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) |
| 256 | endif |
Bram Moolenaar | 8d04317 | 2014-01-23 14:24:41 +0100 | [diff] [blame] | 257 | " call Dret("s:VimEnter") |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 258 | endfun |
| 259 | |
| 260 | " --------------------------------------------------------------------- |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 261 | " NetrwStatusLine: {{{1 |
| 262 | fun! NetrwStatusLine() |
Bram Moolenaar | af48b09 | 2006-03-14 22:51:38 +0000 | [diff] [blame] | 263 | " let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") |
| 264 | if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 265 | let &stl= s:netrw_explore_stl |
| 266 | if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif |
| 267 | if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif |
| 268 | return "" |
| 269 | else |
| 270 | return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen |
| 271 | endif |
| 272 | endfun |
| 273 | |
| 274 | " ------------------------------------------------------------------------ |
| 275 | " NetUserPass: set username and password for subsequent ftp transfer {{{1 |
| 276 | " Usage: :call NetUserPass() -- will prompt for userid and password |
| 277 | " :call NetUserPass("uid") -- will prompt for password |
| 278 | " :call NetUserPass("uid","password") -- sets global userid and password |
| 279 | fun! NetUserPass(...) |
| 280 | |
| 281 | " get/set userid |
| 282 | if a:0 == 0 |
| 283 | " call Dfunc("NetUserPass(a:0<".a:0.">)") |
| 284 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 285 | " via prompt |
| 286 | let g:netrw_uid= input('Enter username: ') |
| 287 | endif |
| 288 | else " from command line |
| 289 | " call Dfunc("NetUserPass(a:1<".a:1.">) {") |
| 290 | let g:netrw_uid= a:1 |
| 291 | endif |
| 292 | |
| 293 | " get password |
| 294 | if a:0 <= 1 " via prompt |
| 295 | " call Decho("a:0=".a:0." case <=1:") |
| 296 | let g:netrw_passwd= inputsecret("Enter Password: ") |
| 297 | else " from command line |
| 298 | " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") |
| 299 | let g:netrw_passwd=a:2 |
| 300 | endif |
| 301 | " call Dret("NetUserPass") |
| 302 | endfun |
| 303 | |
| 304 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 305 | " Modelines And Restoration: {{{1 |
| 306 | let &cpo= s:keepcpo |
| 307 | unlet s:keepcpo |
| 308 | " vim:ts=8 fdm=marker |