netrwPlugin.vim (7745B)
1 " Creator: Charles E Campbell 2 " Previous Maintainer: Luca Saccarola <github.e41mv@aleeas.com> 3 " Maintainer: This runtime file is looking for a new maintainer. 4 " Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{ 5 " Permission is hereby granted to use and distribute this code, 6 " with or without modifications, provided that this copyright 7 " notice is copied with it. Like anything else that's free, 8 " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided 9 " *as is* and comes with no warranty of any kind, either 10 " expressed or implied. By using this plugin, you agree that 11 " in no event will the copyright holder be liable for any damages 12 " resulting from the use of this software. }}} 13 14 if &cp || exists("g:loaded_netrwPlugin") 15 finish 16 endif 17 18 let g:loaded_netrwPlugin = "v184" 19 20 let s:keepcpo = &cpo 21 set cpo&vim 22 23 " Local Browsing Autocmds: {{{ 24 25 augroup FileExplorer 26 au! 27 au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif 28 au BufEnter * sil call s:LocalBrowse(expand("<amatch>")) 29 au VimEnter * sil call s:VimEnter(expand("<amatch>")) 30 if has("win32") 31 au BufEnter .* sil call s:LocalBrowse(expand("<amatch>")) 32 endif 33 augroup END 34 35 " }}} 36 " Network Browsing Reading Writing: {{{ 37 38 augroup Network 39 au! 40 au BufReadCmd file://* call netrw#FileUrlEdit(expand("<amatch>")) 41 au BufReadCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "sil doau BufReadPost ".fnameescape(expand("<amatch>")) 42 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>")) 43 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>")) 44 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>")) 45 try 46 au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) 47 catch /^Vim\%((\a\+)\)\=:E216/ 48 au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) 49 endtry 50 augroup END 51 52 " }}} 53 " Commands: :Nread, :Nwrite, :NetUserPass {{{ 54 55 command! -count=1 -nargs=* Nread let s:svpos= winsaveview()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call winrestview(s:svpos) 56 command! -range=% -nargs=* Nwrite let s:svpos= winsaveview()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call winrestview(s:svpos) 57 command! -nargs=* NetUserPass call netrw#NetUserPass(<f-args>) 58 command! -nargs=* Nsource let s:svpos= winsaveview()<bar>call netrw#NetSource(<f-args>)<bar>call winrestview(s:svpos) 59 command! -nargs=? Ntree call netrw#SetTreetop(1,<q-args>) 60 61 " }}} 62 " Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{ 63 64 command! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>, 0, 0+<bang>0, <q-args>) 65 command! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>, 1, 0+<bang>0, <q-args>) 66 command! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>, 1, 2+<bang>0, <q-args>) 67 command! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>, 1, 4+<bang>0, <q-args>) 68 command! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>, 0, 6, <q-args>) 69 command! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(<count>, <bang>0, <q-args>) 70 command! -nargs=* -bar -bang Nexplore call netrw#Explore(-1, 0, 0, <q-args>) 71 command! -nargs=* -bar -bang Pexplore call netrw#Explore(-2, 0, 0, <q-args>) 72 73 " }}} 74 " Maps: {{{ 75 76 if exists("g:netrw_usetab") && g:netrw_usetab 77 if maparg('<c-tab>','n') == "" 78 nmap <unique> <c-tab> <Plug>NetrwShrink 79 endif 80 nno <silent> <Plug>NetrwShrink :call netrw#Shrink()<cr> 81 endif 82 83 " }}} 84 " LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{ 85 86 function! s:LocalBrowse(dirname) 87 " do not trigger in the terminal 88 " https://github.com/vim/vim/issues/16463 89 if &buftype ==# 'terminal' 90 return 91 endif 92 93 if !exists("s:vimentered") 94 " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, 95 " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. 96 return 97 endif 98 99 if has("amiga") 100 " The check against '' is made for the Amiga, where the empty 101 " string is the current directory and not checking would break 102 " things such as the help command. 103 if a:dirname != '' && isdirectory(a:dirname) 104 sil! call netrw#LocalBrowseCheck(a:dirname) 105 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt 106 exe w:netrw_bannercnt 107 endif 108 endif 109 elseif isdirectory(a:dirname) 110 " Jul 13, 2021: for whatever reason, preceding the following call with 111 " a sil! causes an unbalanced if-endif vim error 112 call netrw#LocalBrowseCheck(a:dirname) 113 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt 114 exe w:netrw_bannercnt 115 endif 116 endif 117 endfunction 118 119 " }}} 120 " s:VimEnter: after all vim startup stuff is done, this function is called. {{{ 121 " Its purpose: to look over all windows and run s:LocalBrowse() on 122 " them, which checks if they're directories and will create a directory 123 " listing when appropriate. 124 " It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() 125 " has already been called. 126 function! s:VimEnter(dirname) 127 if has('nvim') || v:version < 802 128 " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters 129 " error with neovim. I suspect its because neovim hasn't updated with recent 130 " vim patches. As is, this code will have problems with popup terminals 131 " instantiated before the VimEnter event runs. 132 " Ingo Karkat : E488 also in Vim 8.1.1602 133 let curwin = winnr() 134 let s:vimentered = 1 135 windo call s:LocalBrowse(expand("%:p")) 136 exe curwin."wincmd w" 137 else 138 " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and 139 " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. 140 let s:vimentered = 1 141 call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) 142 endif 143 endfunction 144 145 " }}} 146 " Deprecated: {{{ 147 148 function NetUserPass(...) 149 call netrw#msg#Deprecate('NetUserPass', 'v185', { 150 \ 'vim': 'netrw#NetUserPass()', 151 \ 'nvim': 'netrw#NetUserPass()' 152 \}) 153 if a:0 154 call netrw#NetUserPass(a:000) 155 else 156 call netrw#NetUserPass() 157 endif 158 endfunction 159 160 " }}} 161 162 let &cpo= s:keepcpo 163 unlet s:keepcpo 164 165 " vim:ts=8 sts=4 sw=4 et fdm=marker