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 |
| 2 | " PLUGIN PORTION |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 3 | " Date: Oct 27, 2005 |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4 | " Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz> |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 5 | " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim |
| 6 | " Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{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 | |
| 20 | " --------------------------------------------------------------------- |
| 21 | " Load Once: {{{1 |
| 22 | if exists("g:loaded_netrw") |
| 23 | finish |
| 24 | endif |
Bram Moolenaar | 8349fd7 | 2005-10-12 20:52:20 +0000 | [diff] [blame] | 25 | if v:version < 700 |
| 26 | echohl WarningMsg | echo "***netrw*** you need vim version 7.0 for this version of netrw" | echohl None |
| 27 | finish |
| 28 | endif |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 29 | let s:keepcpo= &cpo |
| 30 | set cpo&vim |
| 31 | |
| 32 | " --------------------------------------------------------------------- |
| 33 | " Public Interface: {{{1 |
| 34 | |
| 35 | " Local Browsing: {{{2 |
| 36 | augroup FileExplorer |
| 37 | au! |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 38 | au BufEnter * silent! call s:LocalBrowse(expand("<amatch>")) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 39 | augroup END |
| 40 | |
| 41 | " Network Browsing Reading Writing: {{{2 |
| 42 | augroup Network |
| 43 | au! |
| 44 | if has("win32") || has("win95") || has("win64") || has("win16") |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 45 | au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>")) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 46 | else |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 47 | au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>")) |
| 48 | au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://localhost/\(.*\)','\1',"")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>")) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 49 | endif |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 50 | au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'Nread 0r "'.expand("<amatch>").'"'|exe "silent doau BufReadPost ".expand("<amatch>") |
| 51 | au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau FileReadPre ".expand("<amatch>")|exe 'Nread "' .expand("<amatch>").'"'|exe "silent doau FileReadPost ".expand("<amatch>") |
| 52 | au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe 'Nwrite "' .expand("<amatch>").'"'|exe "silent doau BufWritePost ".expand("<amatch>") |
| 53 | au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau FileWritePre ".expand("<amatch>")|exe "'[,']".'Nwrite "' .expand("<amatch>").'"'|exe "silent doau FileWritePost ".expand("<amatch>") |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 54 | augroup END |
| 55 | |
| 56 | " Commands: :Nread, :Nwrite, :NetUserPass {{{2 |
| 57 | com! -nargs=* Nread call netrw#NetSavePosn()<bar>call netrw#NetRead(<f-args>)<bar>call netrw#NetRestorePosn() |
| 58 | com! -range=% -nargs=* Nwrite call netrw#NetSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetRestorePosn() |
| 59 | com! -nargs=* NetUserPass call NetUserPass(<f-args>) |
| 60 | |
| 61 | " Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2 |
Bram Moolenaar | 8349fd7 | 2005-10-12 20:52:20 +0000 | [diff] [blame] | 62 | com! -nargs=? -bar -bang -count=0 Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>) |
| 63 | com! -nargs=? -bar -bang -count=0 Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>) |
| 64 | com! -nargs=? -bar -bang -count=0 Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>) |
| 65 | com! -nargs=? -bar -bang -count=0 Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>) |
| 66 | com! -nargs=? -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>) |
| 67 | com! -nargs=? -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 68 | |
| 69 | " Commands: NetrwSettings {{{2 |
| 70 | com! -nargs=0 NetrwSettings :call netrwSettings#NetrwSettings() |
| 71 | |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 72 | " Maps: |
| 73 | if !hasmapto('<Plug>NetrwBrowseX') |
| 74 | nmap <unique> gx <Plug>NetrwBrowseX |
| 75 | endif |
| 76 | nno <silent> <Plug>NetrwBrowseX :call netrw#NetBrowseX(expand("<cWORD>"),0)<cr> |
| 77 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 78 | " --------------------------------------------------------------------- |
| 79 | " LocalBrowse: {{{2 |
| 80 | fun! s:LocalBrowse(dirname) |
| 81 | " unfortunate interaction -- debugging calls can't be used here; |
| 82 | " the BufEnter event causes triggering when attempts to write to |
| 83 | " the DBG buffer are made. |
| 84 | if isdirectory(a:dirname) |
Bram Moolenaar | b8a7b56 | 2006-02-01 21:47:16 +0000 | [diff] [blame] | 85 | silent! call netrw#DirBrowse(a:dirname) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 86 | endif |
| 87 | " not a directory, ignore it |
| 88 | endfun |
| 89 | |
| 90 | " --------------------------------------------------------------------- |
| 91 | " NetrwStatusLine: {{{1 |
| 92 | fun! NetrwStatusLine() |
| 93 | " let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr(".")." Xline#".w:netrw_explore_line." line#".line(".") |
| 94 | 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") |
| 95 | let &stl= s:netrw_explore_stl |
| 96 | if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif |
| 97 | if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif |
| 98 | return "" |
| 99 | else |
| 100 | return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen |
| 101 | endif |
| 102 | endfun |
| 103 | |
| 104 | " ------------------------------------------------------------------------ |
| 105 | " NetUserPass: set username and password for subsequent ftp transfer {{{1 |
| 106 | " Usage: :call NetUserPass() -- will prompt for userid and password |
| 107 | " :call NetUserPass("uid") -- will prompt for password |
| 108 | " :call NetUserPass("uid","password") -- sets global userid and password |
| 109 | fun! NetUserPass(...) |
| 110 | |
| 111 | " get/set userid |
| 112 | if a:0 == 0 |
| 113 | " call Dfunc("NetUserPass(a:0<".a:0.">)") |
| 114 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 115 | " via prompt |
| 116 | let g:netrw_uid= input('Enter username: ') |
| 117 | endif |
| 118 | else " from command line |
| 119 | " call Dfunc("NetUserPass(a:1<".a:1.">) {") |
| 120 | let g:netrw_uid= a:1 |
| 121 | endif |
| 122 | |
| 123 | " get password |
| 124 | if a:0 <= 1 " via prompt |
| 125 | " call Decho("a:0=".a:0." case <=1:") |
| 126 | let g:netrw_passwd= inputsecret("Enter Password: ") |
| 127 | else " from command line |
| 128 | " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") |
| 129 | let g:netrw_passwd=a:2 |
| 130 | endif |
| 131 | " call Dret("NetUserPass") |
| 132 | endfun |
| 133 | |
| 134 | " ------------------------------------------------------------------------ |
| 135 | " NetReadFixup: this sort of function is typically written by the user {{{1 |
| 136 | " to handle extra junk that their system's ftp dumps |
| 137 | " into the transfer. This function is provided as an |
| 138 | " example and as a fix for a Windows 95 problem: in my |
| 139 | " experience, win95's ftp always dumped four blank lines |
| 140 | " at the end of the transfer. |
| 141 | if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp |
| 142 | fun! NetReadFixup(method, line1, line2) |
| 143 | " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") |
| 144 | if method == 3 " ftp (no <.netrc>) |
| 145 | let fourblanklines= line2 - 3 |
| 146 | silent fourblanklines.",".line2."g/^\s*/d" |
| 147 | endif |
| 148 | " call Dret("NetReadFixup") |
| 149 | endfun |
| 150 | endif |
| 151 | |
| 152 | " ------------------------------------------------------------------------ |
| 153 | " Modelines And Restoration: {{{1 |
| 154 | let &cpo= s:keepcpo |
| 155 | unlet s:keepcpo |
| 156 | " vim:ts=8 fdm=marker |