blob: 42bdbd9b10281a6cc3f916b820bfea6e66a41132 [file] [log] [blame]
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001" netrw.vim: Handles file transfer and remote directory listing across a network
2" PLUGIN PORTION
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003" Date: Sep 08, 2005
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004" Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00005" License: Vim License (see vim's :help license)
6" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
7" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
8" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
11" netrw.vim is provided *as is* and comes with no warranty
12" of any kind, either expressed or implied. By using this
13" plugin, you agree that in no event will the copyright
14" holder be liable for any damages resulting from the use
15" of this software.
16"
17" But be doers of the Word, and not only hearers, deluding your own selves {{{1
18" (James 1:22 RSV)
19" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
20
21" ---------------------------------------------------------------------
22" Load Once: {{{1
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000023let s:keepcpo= &cpo
24set cpo&vim
25
26" ---------------------------------------------------------------------
27" Public Interface: {{{1
28
29" Local Browsing: {{{2
30augroup FileExplorer
31 au!
32 au BufEnter * call s:LocalBrowse(expand("<amatch>"))
33augroup END
34
35" Network Browsing Reading Writing: {{{2
36augroup Network
37 au!
38 if has("win32") || has("win95") || has("win64") || has("win16")
39 au BufReadCmd file://* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e '.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>")
40 else
41 au BufReadCmd file:///* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e /'.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>")
42 au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e /'.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>")
43 endif
44 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>")
45 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<amatch>")|exe "Nread " .expand("<amatch>")|exe "silent doau FileReadPost ".expand("<amatch>")
46 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe "Nwrite " .expand("<amatch>")|exe "silent doau BufWritePost ".expand("<amatch>")
47 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe "'[,']Nwrite " .expand("<amatch>")|exe "silent doau FileWritePost ".expand("<amatch>")
48augroup END
49
50" Commands: :Nread, :Nwrite, :NetUserPass {{{2
51com! -nargs=* Nread call netrw#NetSavePosn()<bar>call netrw#NetRead(<f-args>)<bar>call netrw#NetRestorePosn()
52com! -range=% -nargs=* Nwrite call netrw#NetSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetRestorePosn()
53com! -nargs=* NetUserPass call NetUserPass(<f-args>)
54
55" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
56com! -nargs=? -bar -bang -count=0 Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
57com! -nargs=? -bar -bang -count=0 Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
58com! -nargs=? -bar -bang -count=0 Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
59com! -nargs=? -bar -bang -count=0 Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
60com! -nargs=? -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
61com! -nargs=? -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
62
63" Commands: NetrwSettings {{{2
64com! -nargs=0 NetrwSettings :call NetrwSettings#NetrwSettings()
65
66" ---------------------------------------------------------------------
67" LocalBrowse: {{{2
68fun! s:LocalBrowse(dirname)
69 " unfortunate interaction -- debugging calls can't be used here;
70 " the BufEnter event causes triggering when attempts to write to
71 " the DBG buffer are made.
72 if isdirectory(a:dirname)
73 call netrw#DirBrowse(a:dirname)
74 endif
75 " not a directory, ignore it
76endfun
77
78" ---------------------------------------------------------------------
79" NetrwStatusLine: {{{1
80fun! NetrwStatusLine()
81" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr(".")." Xline#".w:netrw_explore_line." line#".line(".")
82 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")
83 let &stl= s:netrw_explore_stl
84 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
85 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
86 return ""
87 else
88 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
89 endif
90endfun
91
92" ------------------------------------------------------------------------
93" NetUserPass: set username and password for subsequent ftp transfer {{{1
94" Usage: :call NetUserPass() -- will prompt for userid and password
95" :call NetUserPass("uid") -- will prompt for password
96" :call NetUserPass("uid","password") -- sets global userid and password
97fun! NetUserPass(...)
98
99 " get/set userid
100 if a:0 == 0
101" call Dfunc("NetUserPass(a:0<".a:0.">)")
102 if !exists("g:netrw_uid") || g:netrw_uid == ""
103 " via prompt
104 let g:netrw_uid= input('Enter username: ')
105 endif
106 else " from command line
107" call Dfunc("NetUserPass(a:1<".a:1.">) {")
108 let g:netrw_uid= a:1
109 endif
110
111 " get password
112 if a:0 <= 1 " via prompt
113" call Decho("a:0=".a:0." case <=1:")
114 let g:netrw_passwd= inputsecret("Enter Password: ")
115 else " from command line
116" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
117 let g:netrw_passwd=a:2
118 endif
119" call Dret("NetUserPass")
120endfun
121
122" ------------------------------------------------------------------------
123" NetReadFixup: this sort of function is typically written by the user {{{1
124" to handle extra junk that their system's ftp dumps
125" into the transfer. This function is provided as an
126" example and as a fix for a Windows 95 problem: in my
127" experience, win95's ftp always dumped four blank lines
128" at the end of the transfer.
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000129if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000130 fun! NetReadFixup(method, line1, line2)
131" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
132 if method == 3 " ftp (no <.netrc>)
133 let fourblanklines= line2 - 3
134 silent fourblanklines.",".line2."g/^\s*/d"
135 endif
136" call Dret("NetReadFixup")
137 endfun
138endif
139
140let &cpo= s:keepcpo
141unlet s:keepcpo
142" ------------------------------------------------------------------------
143" Modelines: {{{1
144" vim:ts=8 fdm=marker