robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f29b3b5d45
master
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 14if & cp || exists ( "g:loaded_netrwPlugin" ) 15finish 16endif 17 18let g: loaded_netrwPlugin = "v184" 19 20let s: keepcpo = & cpo 21set cpo & vim 22 23" Local Browsing Autocmds: {{{ 24 25augroup FileExplorer 26au ! 27au BufLeave * if & ft != "netrw" |let w: netrw_prvfile = expand ( "%:p" ) |endif 28au BufEnter * sil call s: LocalBrowse ( expand ( "<amatch>" )) 29au VimEnter * sil call s: VimEnter ( expand ( "<amatch>" )) 30if has ( "win32" ) 31au BufEnter . * sil call s: LocalBrowse ( expand ( "<amatch>" )) 32endif 33augroup END 34 35" }}} 36" Network Browsing Reading Writing: {{{ 37 38augroup Network 39au ! 40au BufReadCmd file:// * call netrw#FileUrlEdit ( expand ( "<amatch>" )) 41au 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>" )) 42au FileReadCmd ftp:// * , rcp:// * , scp:// * , file:// * , dav:// * , davs:// * , rsync:// * , sftp:// * exe "sil doau FileReadPre " . fnameescape ( expand ( "<amatch>" )) |call netrw#Nread ( 1 , expand ( "<amatch>" )) |exe "sil doau FileReadPost " . fnameescape ( expand ( "<amatch>" )) 43au 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>" )) 44au 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>" )) 45try 46au SourceCmd ftp:// * , rcp:// * , scp:// * , http:// * , file:// * , https:// * , dav:// * , davs:// * , rsync:// * , sftp:// * exe 'Nsource ' . fnameescape ( expand ( "<amatch>" )) 47catch /^Vim\%((\a\+)\)\=:E216/ 48au SourcePre ftp:// * , rcp:// * , scp:// * , http:// * , file:// * , https:// * , dav:// * , davs:// * , rsync:// * , sftp:// * exe 'Nsource ' . fnameescape ( expand ( "<amatch>" )) 49endtry 50augroup END 51 52" }}} 53" Commands: :Nread, :Nwrite, :NetUserPass {{{ 54 55command ! -count = 1 -nargs = * Nread let s:svpos= winsaveview()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call winrestview(s:svpos) 56command ! -range = % -nargs = * Nwrite let s:svpos= winsaveview()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call winrestview(s:svpos) 57command ! -nargs = * NetUserPass call netrw#NetUserPass(<f-args>) 58command ! -nargs = * Nsource let s:svpos= winsaveview()<bar>call netrw#NetSource(<f-args>)<bar>call winrestview(s:svpos) 59command ! -nargs = ? Ntree call netrw#SetTreetop(1,<q-args>) 60 61" }}} 62" Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{ 63 64command ! -nargs = * -bar -bang -count = 0 -complete = dir Explore call netrw#Explore(<count>, 0, 0+<bang>0, <q-args>) 65command ! -nargs = * -bar -bang -count = 0 -complete = dir Sexplore call netrw#Explore(<count>, 1, 0+<bang>0, <q-args>) 66command ! -nargs = * -bar -bang -count = 0 -complete = dir Hexplore call netrw#Explore(<count>, 1, 2+<bang>0, <q-args>) 67command ! -nargs = * -bar -bang -count = 0 -complete = dir Vexplore call netrw#Explore(<count>, 1, 4+<bang>0, <q-args>) 68command ! -nargs = * -bar -count = 0 -complete = dir Texplore call netrw#Explore(<count>, 0, 6, <q-args>) 69command ! -nargs = * -bar -bang -count = 0 -complete = dir Lexplore call netrw#Lexplore(<count>, <bang>0, <q-args>) 70command ! -nargs = * -bar -bang Nexplore call netrw#Explore(-1, 0, 0, <q-args>) 71command ! -nargs = * -bar -bang Pexplore call netrw#Explore(-2, 0, 0, <q-args>) 72 73" }}} 74" Maps: {{{ 75 76if exists ( "g:netrw_usetab" ) && g: netrw_usetab 77if maparg ( '<c-tab>' , 'n' ) == "" 78nmap <unique> < c-tab > < Plug > NetrwShrink 79endif 80nno <silent> < Plug > NetrwShrink :call netrw#Shrink()< cr > 81endif 82 83" }}} 84" LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{ 85 86function ! s: LocalBrowse ( dirname ) 87" do not trigger in the terminal 88" https://github.com/vim/vim/issues/16463 89if & buftype ==# 'terminal' 90return 91endif 92 93if ! 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. 96return 97endif 98 99if 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. 103if a: dirname != '' && isdirectory ( a: dirname ) 104sil ! call netrw#LocalBrowseCheck ( a: dirname ) 105if exists ( "w:netrw_bannercnt" ) && line ( '.' ) < w: netrw_bannercnt 106exe w: netrw_bannercnt 107endif 108endif 109elseif 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 112call netrw#LocalBrowseCheck ( a: dirname ) 113if exists ( "w:netrw_bannercnt" ) && line ( '.' ) < w: netrw_bannercnt 114exe w: netrw_bannercnt 115endif 116endif 117endfunction 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. 126function ! s: VimEnter ( dirname ) 127if 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 133let curwin = winnr () 134let s: vimentered = 1 135windo call s:LocalBrowse(expand("%:p")) 136exe curwin . "wincmd w" 137else 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. 140let s: vimentered = 1 141call range ( 1 , winnr ( '$' )) ->map ({ _ , v ->win_execute ( win_getid ( v ), 'call expand("%:p")->s:LocalBrowse()' )}) 142endif 143endfunction 144 145" }}} 146" Deprecated: {{{ 147 148function NetUserPass (...) 149call netrw#msg#Deprecate ( 'NetUserPass' , 'v185' , { 150 \'vim' : 'netrw#NetUserPass()' , 151 \'nvim' : 'netrw#NetUserPass()' 152 \}) 153if a: 0 154call netrw#NetUserPass ( a: 000 ) 155else 156call netrw#NetUserPass () 157endif 158endfunction 159 160" }}} 161 162let & cpo = s: keepcpo 163unlet s: keepcpo 164 165" vim:ts=8 sts=4 sw=4 et fdm=marker