blob: 9833e2b1707d01e6bb6df825099324a66833fe96 [file] [log] [blame]
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00001" netrwPlugin.vim: Handles file transfer and remote directory listing across a network
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +00002" PLUGIN SECTION
Bram Moolenaaradc21822011-04-01 18:03:16 +02003" Date: Feb 10, 2011
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +00004" Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00005" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006" Copyright: Copyright (C) 1999-2008 Charles E. Campbell, Jr. {{{1
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007" 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" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000019" Load Once: {{{1
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000020if &cp || exists("g:loaded_netrwPlugin")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000021 finish
22endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020023let g:loaded_netrwPlugin = "v141"
Bram Moolenaar5c736222010-01-06 20:54:52 +010024if v:version < 702
25 echohl WarningMsg | echo "***netrw*** you need vim version 7.2 for this version of netrw" | echohl None
Bram Moolenaar8349fd72005-10-12 20:52:20 +000026 finish
27endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010028let s:keepcpo = &cpo
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000029set cpo&vim
30
31" ---------------------------------------------------------------------
32" Public Interface: {{{1
33
34" Local Browsing: {{{2
35augroup FileExplorer
36 au!
Bram Moolenaaradc21822011-04-01 18:03:16 +020037" au BufReadCmd *[/\\] sil! call s:LocalBrowse(expand("<amatch>"))
38" au BufEnter *[^/\\] sil! call s:LocalBrowse(expand("<amatch>"))
39" au VimEnter *[^/\\] sil! call s:VimEnter(expand("<amatch>"))
40 au BufEnter * sil! call s:LocalBrowse(expand("<amatch>"))
41 au VimEnter * sil! call s:VimEnter(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000042 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaaradc21822011-04-01 18:03:16 +020043 au BufEnter .* sil! call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000044 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000045augroup END
46
47" Network Browsing Reading Writing: {{{2
48augroup Network
49 au!
50 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaaradc21822011-04-01 18:03:16 +020051 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>"))
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000052 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020053 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>"))
54 au BufReadCmd file://localhost/* call netrw#FileUrlRead(substitute(expand("<amatch>")),'file://localhost/','file:///','')
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000055 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010056 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(expand("<amatch>"))
57 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau FileReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(1,expand("<amatch>"))|exe "silent doau FileReadPost ".fnameescape(expand("<amatch>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +000058 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "silent doau BufWritePost ".fnameescape(expand("<amatch>"))
59 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "silent doau FileWritePost ".fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000060 try
Bram Moolenaare37d50a2008-08-06 17:06:04 +000061 au SourceCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000062 catch /^Vim\%((\a\+)\)\=:E216/
Bram Moolenaare37d50a2008-08-06 17:06:04 +000063 au SourcePre ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000064 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000065augroup END
66
67" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000068com! -count=1 -nargs=* Nread call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn()
69com! -range=% -nargs=* Nwrite call netrw#NetrwSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000070com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaarf2330482008-06-24 20:19:36 +000071com! -nargs=* Nsource call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000072
73" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000074com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
75com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
76com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
77com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
78com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
79com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
80com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000081
82" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000083com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
84com! -bang NetrwClean call netrw#NetrwClean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000085
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000086" Maps:
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020087if !exists("g:netrw_nogx") && maparg('gx','n') == ""
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000088 if !hasmapto('<Plug>NetrwBrowseX')
89 nmap <unique> gx <Plug>NetrwBrowseX
90 endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000091 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<cr>
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000092endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000093
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000094" ---------------------------------------------------------------------
95" LocalBrowse: {{{2
96fun! s:LocalBrowse(dirname)
97 " unfortunate interaction -- debugging calls can't be used here;
98 " the BufEnter event causes triggering when attempts to write to
99 " the DBG buffer are made.
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000100" echomsg "dirname<".a:dirname.">"
101 if has("amiga")
102 " The check against '' is made for the Amiga, where the empty
103 " string is the current directory and not checking would break
104 " things such as the help command.
105 if a:dirname != '' && isdirectory(a:dirname)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200106 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000107 endif
108 elseif isdirectory(a:dirname)
109" echomsg "dirname<".dirname."> isdir"
Bram Moolenaaradc21822011-04-01 18:03:16 +0200110 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000111 endif
112 " not a directory, ignore it
113endfun
114
115" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200116" s:VimEnter: {{{2
117fun! s:VimEnter(dirname)
Bram Moolenaar477db062010-07-28 18:17:41 +0200118 let curwin= winnr()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200119 windo if a:dirname != expand("%")|call s:LocalBrowse(expand("%:p"))|endif
Bram Moolenaar477db062010-07-28 18:17:41 +0200120 exe curwin."wincmd w"
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200121endfun
122
123" ---------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000124" NetrwStatusLine: {{{1
125fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000126" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
127 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")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000128 let &stl= s:netrw_explore_stl
129 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
130 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
131 return ""
132 else
133 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
134 endif
135endfun
136
137" ------------------------------------------------------------------------
138" NetUserPass: set username and password for subsequent ftp transfer {{{1
139" Usage: :call NetUserPass() -- will prompt for userid and password
140" :call NetUserPass("uid") -- will prompt for password
141" :call NetUserPass("uid","password") -- sets global userid and password
142fun! NetUserPass(...)
143
144 " get/set userid
145 if a:0 == 0
146" call Dfunc("NetUserPass(a:0<".a:0.">)")
147 if !exists("g:netrw_uid") || g:netrw_uid == ""
148 " via prompt
149 let g:netrw_uid= input('Enter username: ')
150 endif
151 else " from command line
152" call Dfunc("NetUserPass(a:1<".a:1.">) {")
153 let g:netrw_uid= a:1
154 endif
155
156 " get password
157 if a:0 <= 1 " via prompt
158" call Decho("a:0=".a:0." case <=1:")
159 let g:netrw_passwd= inputsecret("Enter Password: ")
160 else " from command line
161" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
162 let g:netrw_passwd=a:2
163 endif
164" call Dret("NetUserPass")
165endfun
166
167" ------------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000168" Modelines And Restoration: {{{1
169let &cpo= s:keepcpo
170unlet s:keepcpo
171" vim:ts=8 fdm=marker