1" netrwPlugin.vim: Handles file transfer and remote directory listing across a network 2" PLUGIN SECTION 3" Date: Dec 31, 2013 4" Maintainer: Charles E Campbell <[email protected]> 5" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim 6" Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{1 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 20if &cp || exists("g:loaded_netrwPlugin") 21 finish 22endif 23let g:loaded_netrwPlugin = "v150" 24if v:version < 702 25 echohl WarningMsg 26 echo "***warning*** you need vim version 7.2 for this version of netrw" 27 echohl None 28 finish 29endif 30if v:version < 703 || (v:version == 703 && !has("patch465")) 31 echohl WarningMsg 32 echo "***warning*** this version of netrw needs vim 7.3.465 or later" 33 echohl Normal 34 finish 35endif 36let s:keepcpo = &cpo 37set cpo&vim 38"DechoRemOn 39 40" --------------------------------------------------------------------- 41" Public Interface: {{{1 42 43" Local Browsing Autocmds: {{{2 44augroup FileExplorer 45 au! 46 au BufEnter * sil call s:LocalBrowse(expand("<amatch>")) 47 au VimEnter * sil call s:VimEnter(expand("<amatch>")) 48 if has("win32") || has("win95") || has("win64") || has("win16") 49 au BufEnter .* sil call s:LocalBrowse(expand("<amatch>")) 50 endif 51augroup END 52 53" Network Browsing Reading Writing: {{{2 54augroup Network 55 au! 56 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>")) 57 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>")) 58 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,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>")) 59 au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau BufWritePost ".fnameescape(expand("<amatch>")) 60 au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau FileWritePost ".fnameescape(expand("<amatch>")) 61 try 62 au SourceCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) 63 catch /^Vim\%((\a\+)\)\=:E216/ 64 au SourcePre ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>")) 65 endtry 66augroup END 67 68" Commands: :Nread, :Nwrite, :NetUserPass {{{2 69com! -count=1 -nargs=* Nread call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn() 70com! -range=% -nargs=* Nwrite call netrw#NetrwSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetrwRestorePosn() 71com! -nargs=* NetUserPass call NetUserPass(<f-args>) 72com! -nargs=* Nsource call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn() 73com! -nargs=? Ntree call netrw#NetrwSetTreetop(<q-args>) 74 75" Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2 76com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>) 77com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>) 78com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>) 79com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>) 80com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>) 81com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>) 82com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>) 83com! -nargs=* -bar -complete=dir Lexplore call netrw#Lexplore(<q-args>) 84 85" Commands: NetrwSettings {{{2 86com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() 87com! -bang NetrwClean call netrw#NetrwClean(<bang>0) 88 89" Maps: 90if !exists("g:netrw_nogx") && maparg('gx','n') == "" 91 if !hasmapto('<Plug>NetrwBrowseX') 92 nmap <unique> gx <Plug>NetrwBrowseX 93 endif 94 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cfile>"),0)<cr> 95endif 96 97" --------------------------------------------------------------------- 98" LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2 99fun! s:LocalBrowse(dirname) 100 " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here. 101 " Otherwise, the BufEnter event gets triggered when attempts to write to 102 " the DBG buffer are made. 103 104 if !exists("s:vimentered") 105 " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, 106 " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. 107" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") 108" call Dret("s:LocalBrowse") 109 return 110 endif 111 112" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") 113 114 if has("amiga") 115 " The check against '' is made for the Amiga, where the empty 116 " string is the current directory and not checking would break 117 " things such as the help command. 118" call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") 119 if a:dirname != '' && isdirectory(a:dirname) 120 sil! call netrw#LocalBrowseCheck(a:dirname) 121 endif 122 123 elseif isdirectory(a:dirname) 124" call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, not amiga)") 125 sil! call netrw#LocalBrowseCheck(a:dirname) 126 127 else 128 " not a directory, ignore it 129" call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") 130 endif 131 132" call Dret("s:LocalBrowse") 133endfun 134 135" --------------------------------------------------------------------- 136" s:VimEnter: after all vim startup stuff is done, this function is called. {{{2 137" Its purpose: to look over all windows and run s:LocalBrowse() on 138" them, which checks if they're directories and will create a directory 139" listing when appropriate. 140" It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() 141" has already been called. 142fun! s:VimEnter(dirname) 143" call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") 144 let curwin = winnr() 145 let s:vimentered = 1 146 windo call s:LocalBrowse(expand("%:p")) 147 exe curwin."wincmd w" 148" call Dret("s:VimEnter") 149endfun 150 151" --------------------------------------------------------------------- 152" NetrwStatusLine: {{{1 153fun! NetrwStatusLine() 154" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") 155 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") 156 let &stl= s:netrw_explore_stl 157 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif 158 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif 159 return "" 160 else 161 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen 162 endif 163endfun 164 165" ------------------------------------------------------------------------ 166" NetUserPass: set username and password for subsequent ftp transfer {{{1 167" Usage: :call NetUserPass() -- will prompt for userid and password 168" :call NetUserPass("uid") -- will prompt for password 169" :call NetUserPass("uid","password") -- sets global userid and password 170fun! NetUserPass(...) 171 172 " get/set userid 173 if a:0 == 0 174" call Dfunc("NetUserPass(a:0<".a:0.">)") 175 if !exists("g:netrw_uid") || g:netrw_uid == "" 176 " via prompt 177 let g:netrw_uid= input('Enter username: ') 178 endif 179 else " from command line 180" call Dfunc("NetUserPass(a:1<".a:1.">) {") 181 let g:netrw_uid= a:1 182 endif 183 184 " get password 185 if a:0 <= 1 " via prompt 186" call Decho("a:0=".a:0." case <=1:") 187 let g:netrw_passwd= inputsecret("Enter Password: ") 188 else " from command line 189" call Decho("a:0=".a:0." case >1: a:2<".a:2.">") 190 let g:netrw_passwd=a:2 191 endif 192" call Dret("NetUserPass") 193endfun 194 195" ------------------------------------------------------------------------ 196" Modelines And Restoration: {{{1 197let &cpo= s:keepcpo 198unlet s:keepcpo 199" vim:ts=8 fdm=marker 200