Mercurial > vim
annotate runtime/plugin/netrwPlugin.vim @ 26677:51db19c22522
Added tag v8.2.3867 for changeset b856b797c5d1ef1fcf8a690ed0b35e0a03c73215
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 21 Dec 2021 14:30:04 +0100 |
parents | d4faa2c5211b |
children | b2e8663e6dcc |
rev | line source |
---|---|
534 | 1 " netrwPlugin.vim: Handles file transfer and remote directory listing across a network |
1118 | 2 " PLUGIN SECTION |
25700 | 3 " Date: Feb 09, 2021 |
19099 | 4 " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
534 | 5 " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim |
25700 | 6 " Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1 |
534 | 7 " Permission is hereby granted to use and distribute this code, |
8 " with or without modifications, provided that this copyright | |
9 " notice is copied with it. Like anything else that's free, | |
10 " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided | |
11 " *as is* and comes with no warranty of any kind, either | |
12 " expressed or implied. By using this plugin, you agree that | |
13 " in no event will the copyright holder be liable for any damages | |
14 " resulting from the use of this software. | |
15 " | |
16 " But be doers of the Word, and not only hearers, deluding your own selves {{{1 | |
17 " (James 1:22 RSV) | |
18 " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
19 " Load Once: {{{1 | |
1118 | 20 if &cp || exists("g:loaded_netrwPlugin") |
534 | 21 finish |
22 endif | |
25700 | 23 let g:loaded_netrwPlugin = "v171" |
2034 | 24 let s:keepcpo = &cpo |
534 | 25 set cpo&vim |
5618 | 26 "DechoRemOn |
534 | 27 |
28 " --------------------------------------------------------------------- | |
29 " Public Interface: {{{1 | |
30 | |
5618 | 31 " Local Browsing Autocmds: {{{2 |
534 | 32 augroup FileExplorer |
33 au! | |
5734 | 34 au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif |
5618 | 35 au BufEnter * sil call s:LocalBrowse(expand("<amatch>")) |
36 au VimEnter * sil call s:VimEnter(expand("<amatch>")) | |
1118 | 37 if has("win32") || has("win95") || has("win64") || has("win16") |
5618 | 38 au BufEnter .* sil call s:LocalBrowse(expand("<amatch>")) |
1118 | 39 endif |
534 | 40 augroup END |
41 | |
42 " Network Browsing Reading Writing: {{{2 | |
43 augroup Network | |
44 au! | |
17433 | 45 au BufReadCmd file://* call netrw#FileUrlEdit(expand("<amatch>")) |
46 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>")) | |
6476 | 47 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>")) |
48 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>")) | |
49 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>")) | |
18130 | 50 try |
6476 | 51 au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) |
18130 | 52 catch /^Vim\%((\a\+)\)\=:E216/ |
6476 | 53 au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) |
1118 | 54 endtry |
534 | 55 augroup END |
56 | |
57 " Commands: :Nread, :Nwrite, :NetUserPass {{{2 | |
8148
f5da459c5698
commit https://github.com/vim/vim/commit/e0fa3742ead676a3074a10edadbc955e1a89153d
Christian Brabandt <cb@256bit.org>
parents:
7183
diff
changeset
|
58 com! -count=1 -nargs=* Nread let s:svpos= winsaveview()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call winrestview(s:svpos) |
f5da459c5698
commit https://github.com/vim/vim/commit/e0fa3742ead676a3074a10edadbc955e1a89153d
Christian Brabandt <cb@256bit.org>
parents:
7183
diff
changeset
|
59 com! -range=% -nargs=* Nwrite let s:svpos= winsaveview()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call winrestview(s:svpos) |
534 | 60 com! -nargs=* NetUserPass call NetUserPass(<f-args>) |
8148
f5da459c5698
commit https://github.com/vim/vim/commit/e0fa3742ead676a3074a10edadbc955e1a89153d
Christian Brabandt <cb@256bit.org>
parents:
7183
diff
changeset
|
61 com! -nargs=* Nsource let s:svpos= winsaveview()<bar>call netrw#NetSource(<f-args>)<bar>call winrestview(s:svpos) |
17433 | 62 com! -nargs=? Ntree call netrw#SetTreetop(1,<q-args>) |
534 | 63 |
5618 | 64 " Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2 |
1118 | 65 com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>) |
66 com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>) | |
67 com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>) | |
68 com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>) | |
69 com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>) | |
70 com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>) | |
71 com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>) | |
6476 | 72 com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(<count>,<bang>0,<q-args>) |
534 | 73 |
74 " Commands: NetrwSettings {{{2 | |
1618 | 75 com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() |
5734 | 76 com! -bang NetrwClean call netrw#Clean(<bang>0) |
534 | 77 |
649 | 78 " Maps: |
6476 | 79 if !exists("g:netrw_nogx") |
80 if maparg('gx','n') == "" | |
81 if !hasmapto('<Plug>NetrwBrowseX') | |
82 nmap <unique> gx <Plug>NetrwBrowseX | |
83 endif | |
18594 | 84 nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))<cr> |
1118 | 85 endif |
25700 | 86 if maparg('gx','x') == "" |
6476 | 87 if !hasmapto('<Plug>NetrwBrowseXVis') |
25700 | 88 xmap <unique> gx <Plug>NetrwBrowseXVis |
6476 | 89 endif |
25700 | 90 xno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr> |
6476 | 91 endif |
649 | 92 endif |
7183
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
93 if exists("g:netrw_usetab") && g:netrw_usetab |
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
94 if maparg('<c-tab>','n') == "" |
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
95 nmap <unique> <c-tab> <Plug>NetrwShrink |
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
96 endif |
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
97 nno <silent> <Plug>NetrwShrink :call netrw#Shrink()<cr> |
ffad29dc7eee
commit https://github.com/vim/vim/commit/a0f849ee40cbea3c889345256786b640b0becca2
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
98 endif |
649 | 99 |
534 | 100 " --------------------------------------------------------------------- |
5618 | 101 " LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2 |
534 | 102 fun! s:LocalBrowse(dirname) |
5618 | 103 " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here. |
104 " Otherwise, the BufEnter event gets triggered when attempts to write to | |
534 | 105 " the DBG buffer are made. |
18130 | 106 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
107 if !exists("s:vimentered") |
5618 | 108 " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, |
109 " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. | |
110 " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") | |
111 " call Dret("s:LocalBrowse") | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
112 return |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
113 endif |
5618 | 114 |
115 " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") | |
116 | |
1118 | 117 if has("amiga") |
118 " The check against '' is made for the Amiga, where the empty | |
119 " string is the current directory and not checking would break | |
120 " things such as the help command. | |
5618 | 121 " call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") |
1118 | 122 if a:dirname != '' && isdirectory(a:dirname) |
2751 | 123 sil! call netrw#LocalBrowseCheck(a:dirname) |
6476 | 124 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt |
5734 | 125 exe w:netrw_bannercnt |
126 endif | |
1118 | 127 endif |
5618 | 128 |
1118 | 129 elseif isdirectory(a:dirname) |
5734 | 130 " call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)") |
131 " call Dredir("LocalBrowse ft last set: ","verbose set ft") | |
25700 | 132 " Jul 13, 2021: for whatever reason, preceding the following call with |
133 " a sil! causes an unbalanced if-endif vim error | |
134 call netrw#LocalBrowseCheck(a:dirname) | |
6476 | 135 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt |
5734 | 136 exe w:netrw_bannercnt |
137 endif | |
5618 | 138 |
139 else | |
140 " not a directory, ignore it | |
141 " call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") | |
534 | 142 endif |
5618 | 143 |
144 " call Dret("s:LocalBrowse") | |
534 | 145 endfun |
146 | |
147 " --------------------------------------------------------------------- | |
5618 | 148 " s:VimEnter: after all vim startup stuff is done, this function is called. {{{2 |
149 " Its purpose: to look over all windows and run s:LocalBrowse() on | |
150 " them, which checks if they're directories and will create a directory | |
151 " listing when appropriate. | |
152 " It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() | |
153 " has already been called. | |
2152 | 154 fun! s:VimEnter(dirname) |
5618 | 155 " call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") |
25700 | 156 if has('nvim') || v:version < 802 |
157 " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters | |
158 " error with neovim. I suspect its because neovim hasn't updated with recent | |
159 " vim patches. As is, this code will have problems with popup terminals | |
160 " instantiated before the VimEnter event runs. | |
161 " Ingo Karkat : E488 also in Vim 8.1.1602 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
162 let curwin = winnr() |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
163 let s:vimentered = 1 |
5618 | 164 windo call s:LocalBrowse(expand("%:p")) |
2426 | 165 exe curwin."wincmd w" |
25700 | 166 else |
167 " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and | |
168 " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. | |
169 let s:vimentered = 1 | |
170 call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) | |
171 endif | |
5618 | 172 " call Dret("s:VimEnter") |
2152 | 173 endfun |
174 | |
175 " --------------------------------------------------------------------- | |
534 | 176 " NetrwStatusLine: {{{1 |
177 fun! NetrwStatusLine() | |
755 | 178 " let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") |
179 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") | |
534 | 180 let &stl= s:netrw_explore_stl |
181 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif | |
182 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif | |
183 return "" | |
184 else | |
185 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen | |
186 endif | |
187 endfun | |
188 | |
189 " ------------------------------------------------------------------------ | |
190 " NetUserPass: set username and password for subsequent ftp transfer {{{1 | |
191 " Usage: :call NetUserPass() -- will prompt for userid and password | |
192 " :call NetUserPass("uid") -- will prompt for password | |
193 " :call NetUserPass("uid","password") -- sets global userid and password | |
194 fun! NetUserPass(...) | |
195 | |
196 " get/set userid | |
197 if a:0 == 0 | |
198 " call Dfunc("NetUserPass(a:0<".a:0.">)") | |
199 if !exists("g:netrw_uid") || g:netrw_uid == "" | |
200 " via prompt | |
201 let g:netrw_uid= input('Enter username: ') | |
202 endif | |
203 else " from command line | |
204 " call Dfunc("NetUserPass(a:1<".a:1.">) {") | |
205 let g:netrw_uid= a:1 | |
206 endif | |
207 | |
208 " get password | |
209 if a:0 <= 1 " via prompt | |
210 " call Decho("a:0=".a:0." case <=1:") | |
211 let g:netrw_passwd= inputsecret("Enter Password: ") | |
212 else " from command line | |
213 " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") | |
214 let g:netrw_passwd=a:2 | |
215 endif | |
216 " call Dret("NetUserPass") | |
217 endfun | |
218 | |
219 " ------------------------------------------------------------------------ | |
220 " Modelines And Restoration: {{{1 | |
221 let &cpo= s:keepcpo | |
222 unlet s:keepcpo | |
223 " vim:ts=8 fdm=marker |