blob: 28e1c3ecf85672471c8bf949d9c02b9051756ed7 [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 Moolenaare0fa3742016-02-20 15:47:01 +01003" Date: Feb 08, 2016
Bram Moolenaarff034192013-04-24 18:51:19 +02004" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00005" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaar8d043172014-01-23 14:24:41 +01006" Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{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 Moolenaar46973992017-12-14 19:56:46 +010023let g:loaded_netrwPlugin = "v156"
Bram Moolenaar5c736222010-01-06 20:54:52 +010024let s:keepcpo = &cpo
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000025set cpo&vim
Bram Moolenaar8d043172014-01-23 14:24:41 +010026"DechoRemOn
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000027
28" ---------------------------------------------------------------------
29" Public Interface: {{{1
30
Bram Moolenaar8d043172014-01-23 14:24:41 +010031" Local Browsing Autocmds: {{{2
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000032augroup FileExplorer
33 au!
Bram Moolenaara6878372014-03-22 21:02:50 +010034 au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010035 au BufEnter * sil call s:LocalBrowse(expand("<amatch>"))
36 au VimEnter * sil call s:VimEnter(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000037 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8d043172014-01-23 14:24:41 +010038 au BufEnter .* sil call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000039 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000040augroup END
41
42" Network Browsing Reading Writing: {{{2
43augroup Network
44 au!
Bram Moolenaar46973992017-12-14 19:56:46 +010045 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>"))
46 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,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>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010047 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,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>"))
48 au 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>"))
49 au 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>"))
50 try
51 au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
52 catch /^Vim\%((\a\+)\)\=:E216/
53 au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000054 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000055augroup END
56
57" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaare0fa3742016-02-20 15:47:01 +010058com! -count=1 -nargs=* Nread let s:svpos= winsaveview()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call winrestview(s:svpos)
59com! -range=% -nargs=* Nwrite let s:svpos= winsaveview()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call winrestview(s:svpos)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000060com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010061com! -nargs=* Nsource let s:svpos= winsaveview()<bar>call netrw#NetSource(<f-args>)<bar>call winrestview(s:svpos)
Bram Moolenaar46973992017-12-14 19:56:46 +010062com! -nargs=? Ntree call netrw#SetTreetop(<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000063
Bram Moolenaar8d043172014-01-23 14:24:41 +010064" Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000065com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
66com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
67com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
68com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
69com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
70com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
71com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010072com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(<count>,<bang>0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000073
74" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000075com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
Bram Moolenaara6878372014-03-22 21:02:50 +010076com! -bang NetrwClean call netrw#Clean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000077
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000078" Maps:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010079if !exists("g:netrw_nogx")
80 if maparg('gx','n') == ""
81 if !hasmapto('<Plug>NetrwBrowseX')
82 nmap <unique> gx <Plug>NetrwBrowseX
83 endif
Bram Moolenaar46973992017-12-14 19:56:46 +010084 nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())<cr>
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000085 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010086 if maparg('gx','v') == ""
87 if !hasmapto('<Plug>NetrwBrowseXVis')
88 vmap <unique> gx <Plug>NetrwBrowseXVis
89 endif
90 vno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr>
91 endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000092endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010093if exists("g:netrw_usetab") && g:netrw_usetab
94 if maparg('<c-tab>','n') == ""
95 nmap <unique> <c-tab> <Plug>NetrwShrink
96 endif
97 nno <silent> <Plug>NetrwShrink :call netrw#Shrink()<cr>
98endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000099
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000100" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +0100101" LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000102fun! s:LocalBrowse(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100103 " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here.
104 " Otherwise, the BufEnter event gets triggered when attempts to write to
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000105 " the DBG buffer are made.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100106
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200107 if !exists("s:vimentered")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100108 " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will,
109 " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined.
110" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)")
111" call Dret("s:LocalBrowse")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200112 return
113 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100114
115" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")")
116
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000117 if has("amiga")
118 " The check against '' is made for the Amiga, where the empty
119 " string is the current directory and not checking would break
120 " things such as the help command.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100121" call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)")
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000122 if a:dirname != '' && isdirectory(a:dirname)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200123 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100124 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +0100125 exe w:netrw_bannercnt
126 endif
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000127 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100128
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000129 elseif isdirectory(a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +0100130" call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)")
131" call Dredir("LocalBrowse ft last set: ","verbose set ft")
Bram Moolenaar46973992017-12-14 19:56:46 +0100132" call Decho("(s:LocalBrowse) COMBAK#23: buf#".bufnr("%")." file<".expand("%")."> line#".line(".")." col#".col("."))
Bram Moolenaaradc21822011-04-01 18:03:16 +0200133 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar46973992017-12-14 19:56:46 +0100134" call Decho("(s:LocalBrowse) COMBAK#24: buf#".bufnr("%")." file<".expand("%")."> line#".line(".")." col#".col("."))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100135 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +0100136 exe w:netrw_bannercnt
Bram Moolenaar46973992017-12-14 19:56:46 +0100137" call Decho("(s:LocalBrowse) COMBAK#25: buf#".bufnr("%")." file<".expand("%")."> line#".line(".")." col#".col("."))
Bram Moolenaara6878372014-03-22 21:02:50 +0100138 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100139
140 else
141 " not a directory, ignore it
142" call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000143 endif
Bram Moolenaar46973992017-12-14 19:56:46 +0100144" call Decho("(s:LocalBrowse) COMBAK#26: buf#".bufnr("%")." file<".expand("%")."> line#".line(".")." col#".col("."))
Bram Moolenaar8d043172014-01-23 14:24:41 +0100145
146" call Dret("s:LocalBrowse")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000147endfun
148
149" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +0100150" s:VimEnter: after all vim startup stuff is done, this function is called. {{{2
151" Its purpose: to look over all windows and run s:LocalBrowse() on
152" them, which checks if they're directories and will create a directory
153" listing when appropriate.
154" It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter()
155" has already been called.
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200156fun! s:VimEnter(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100157" call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200158 let curwin = winnr()
159 let s:vimentered = 1
Bram Moolenaar8d043172014-01-23 14:24:41 +0100160 windo call s:LocalBrowse(expand("%:p"))
Bram Moolenaar477db062010-07-28 18:17:41 +0200161 exe curwin."wincmd w"
Bram Moolenaar8d043172014-01-23 14:24:41 +0100162" call Dret("s:VimEnter")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200163endfun
164
165" ---------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000166" NetrwStatusLine: {{{1
167fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000168" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
169 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 +0000170 let &stl= s:netrw_explore_stl
171 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
172 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
173 return ""
174 else
175 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
176 endif
177endfun
178
179" ------------------------------------------------------------------------
180" NetUserPass: set username and password for subsequent ftp transfer {{{1
181" Usage: :call NetUserPass() -- will prompt for userid and password
182" :call NetUserPass("uid") -- will prompt for password
183" :call NetUserPass("uid","password") -- sets global userid and password
184fun! NetUserPass(...)
185
186 " get/set userid
187 if a:0 == 0
188" call Dfunc("NetUserPass(a:0<".a:0.">)")
189 if !exists("g:netrw_uid") || g:netrw_uid == ""
190 " via prompt
191 let g:netrw_uid= input('Enter username: ')
192 endif
193 else " from command line
194" call Dfunc("NetUserPass(a:1<".a:1.">) {")
195 let g:netrw_uid= a:1
196 endif
197
198 " get password
199 if a:0 <= 1 " via prompt
200" call Decho("a:0=".a:0." case <=1:")
201 let g:netrw_passwd= inputsecret("Enter Password: ")
202 else " from command line
203" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
204 let g:netrw_passwd=a:2
205 endif
206" call Dret("NetUserPass")
207endfun
208
209" ------------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000210" Modelines And Restoration: {{{1
211let &cpo= s:keepcpo
212unlet s:keepcpo
213" vim:ts=8 fdm=marker