"$Id: vimcommander.vim,v 1.54.2.2 2004/02/27 02:23:01 lpenz Exp $ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Name: vimcommander " Description: total-commander-like file manager for vim. " Author: Leandro Penz " Maintainer: Leandro Penz " Url: http://www.vim.org/scripts/script.php?script_id=808 " Licence: This program is free software; you can redistribute it " and/or modify it under the terms of the GNU General Public " License. See http://www.gnu.org/copyleft/gpl.txt " Credits: Patrick Schiel, the author of Opsplorer.vim " (http://www.vim.org/scripts/script.php?script_id=362) " in which this script is based, " Christian Ghisler, the author of Total Commander, for the best " *-commander around. (http://www.ghisler.com) " Mathieu Clabaut , the author of " vimspell, from where I got how to autogenerate the " help from within the script. " Diego Morales, fixes and suggestions. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Section: Documentation " " Documentation should be available by ":help vimcommander" command, once the " script has been copied in you .vim/plugin directory. " " If you do not want the documentation to be installed, just put " let b:vimcommander_install_doc=0 " in your .vimrc, or uncomment the line above. " " The documentation is still available at the end of the script. " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Section: Code " fu! CommanderMappings() noremap :cal OnClick() noremap <2-LeftMouse> :cal OnDoubleClick() noremap :cal OnDoubleClick() noremap :cal GotoNextEntry() noremap :cal GotoPrevEntry() noremap :cal GotoNextNode() noremap :cal GotoPrevNode() noremap :cal BuildParentTree() "total-cmd keys: noremap :cal SwitchBuffer() noremap :cal BuildTree("$HOME") noremap :cal BuildTree("/") noremap / :cal BuildTree("/") "F-keys and aliases: noremap :cal FileView() noremap :cal FileEdit() noremap :cal NewFileEdit() noremap :cal NewFileEdit() noremap :cal FileCopy() noremap :cal FileMove() noremap :cal DirCreate() noremap :cal FileDelete() noremap :cal FileDelete() noremap :cal VimCommanderToggle() noremap :cal VimCommanderToggle() "Panel-dirs noremap :cal GetOrPutDir('l') noremap :cal GetOrPutDir('r') noremap :cal GetOrPutDir('l') noremap :cal GetOrPutDir('r') noremap :cal GetOrPutDir('l') noremap :cal GetOrPutDir('r') noremap o :cal PutDir() noremap :cal PutDir() noremap :cal ExchangeDirs() noremap u :cal ExchangeDirs() noremap :cal RefreshDisplays() noremap r :cal RefreshDisplays() noremap :cal ShowHiddenFilesToggle() noremap h :cal ShowHiddenFilesToggle() "File-selection noremap :cal Select() noremap :cal SelectPattern('*') noremap :cal SelectPattern('*') noremap :cal DeSelectPattern('*') noremap :cal SelectPatternAsk() noremap :cal DeSelectPatternAsk() "Dir history noremap :cal PrevDir() noremap t :cal PrevDir() noremap :cal NextDir() noremap y :cal NextDir() "Misc (some are Opsplorer's) noremap :cal SetMatchPattern() noremap :cal SetMatchPattern() "noremap :cal VimCommanderToggle() "noremap o :cal VimCommanderToggle() endf fu! VimCommanderToggle() if exists("g:vimcommander_loaded") if(g:vimcommander_loaded==1) " its on screen - close cal Close() el " its loaded, but not on screen cal VimCommanderShow() end el cal First() en endf fu!First() cal SaveOpts() cal InitOptions() let s:path_left=getcwd() let s:path_right=getcwd() let s:line_right=2 let s:line_left=2 let g:vimcommander_lastside="VimCommanderLeft" let g:vimcommander_shallcd=0 cal VimCommanderShow() endf fu! VimCommanderShow() if exists("g:vimcommander_loaded") && g:vimcommander_loaded==1 " on screen return end "close all windows let s:buffer_to_load=expand("%:p") "let v:errmsg='' "while v:errmsg=='' " silent! close "endwhile "reset aucmd autocmd! BufEnter VimCommanderLeft autocmd! BufEnter VimCommanderRight autocmd! BufWinLeave VimCommanderLeft autocmd! BufWinLeave VimCommanderRight " create new window let winsize=&lines exe winsize." split VimCommanderRight" let s:bufnr_right=winbufnr(0) " setup mappings, apply options, colors and draw tree cal InitCommanderOptions() cal CommanderMappings() cal InitCommanderColors() cal BuildTree(s:path_right) cal GotoEntry(s:line_right) exe "vs VimCommanderLeft" let s:bufnr_left=winbufnr(0) cal InitCommanderOptions() cal CommanderMappings() cal InitCommanderColors() cal BuildTree(s:path_left) cal GotoEntry(s:line_left) let g:vimcommander_loaded=1 "Goto vimcommander window winc j hide let winnum = bufwinnr(s:bufnr_left) if winnum != -1 " Jump to the existing window if winnr() != winnum exe winnum . 'wincmd w' endif endif if g:vimcommander_lastside=="VimCommanderRight" cal SwitchBuffer() end "norm! z- autocmd BufEnter VimCommanderLeft cal LeftBufEnter() autocmd BufEnter VimCommanderRight cal RightBufEnter() autocmd BufWinLeave VimCommanderLeft cal VimCommanderToggle() autocmd BufWinLeave VimCommanderRight cal VimCommanderToggle() endf fu! GotoEntry(line) exe a:line norm! 4| endf fu! LeftBufEnter() if g:vimcommander_shallcd==1 exe "cd ".MyPath() end let g:vimcommander_lastside="VimCommanderLeft" endf fu! RightBufEnter() if g:vimcommander_shallcd==1 exe "cd ".MyPath() end let g:vimcommander_lastside="VimCommanderRight" endf fu! Close() autocmd! BufEnter VimCommanderLeft autocmd! BufEnter VimCommanderRight autocmd! BufWinLeave VimCommanderLeft autocmd! BufWinLeave VimCommanderRight let winnum = bufwinnr(s:bufnr_left) if winnum != -1 " Jump to the existing window if winnr() != winnum exe winnum . 'wincmd w' endif endif let s:line_left=line('.') silent! close let winnum = bufwinnr(s:bufnr_right) if winnum != -1 " Jump to the existing window if winnr() != winnum exe winnum . 'wincmd w' endif endif let s:line_right=line('.') "silent! close let g:vimcommander_loaded=0 if strlen(s:buffer_to_load)>0 exe "edit +buffer ".s:buffer_to_load else if bufwinnr(s:bufnr_right)!=-1 exe "new +buffer ".s:buffer_to_load exe 'wincmd w' close end end cal LoadOpts() endf fu! SaveOpts() let s:scrollbind=&scrollbind let s:wrap=&wrap let s:nu=&nu let s:buflisted=&buflisted let s:number=&number let s:incsearch=&incsearch endf fu! LoadOpts() if s:scrollbind==1 set scrollbind else set noscrollbind end if s:wrap==1 set wrap else set nowrap end if s:nu==1 set nu else set nonu end if s:buflisted==1 set buflisted else set nobuflisted end if s:number==1 set number else set nonumber end if s:incsearch==1 set incsearch else set noincsearch end endf fu! InitCommanderOptions() silent! setlocal noscrollbind silent! setlocal nowrap silent! setlocal nonu silent! setlocal buftype=nofile silent! setlocal bufhidden=delete silent! setlocal noswapfile silent! setlocal nobuflisted silent! setlocal nonumber silent! setlocal incsearch let b:vimcommander_selected="" let b:vimcommander_prev="" let b:vimcommander_next="" endf fu! InitCommanderColors() sy clear if s:use_colors syntax match VimCommanderSelectedFile '^.> .*' syntax match VimCommanderSelectedDir '^.>+\w*.*' contained contains=VimCommanderNode syntax match VimCommanderPath "^/.*" syntax match VimCommanderDirLine "^..+.*" transparent contains=VimCommanderSelectedDir syntax match VimCommanderFileLine "^.. \w.*" transparent contains=ALL syntax match VimCommanderFile "\w.*" contained syntax match VimCommanderSource "^.. \w*.*\.c$" contained syntax match VimCommanderHeader "^.. \w*.*\.h$" contained syntax match VimCommanderSpecial "^.. \(Makefile\|config.mk\)$" contained hi link VimCommanderPath Label hi link VimCommanderNode Comment "hi link OpsFile Question hi link VimCommanderFile Comment hi link VimCommanderSource Question hi link VimCommanderHeader Include hi link VimCommanderSpecial Function hi link VimCommanderSelectedFile Visual hi link VimCommanderSelectedDir Visual en endf fu! SwitchBuffer() if winbufnr(0) == s:bufnr_left winc l else winc h end endf fu! ProvideBuffer() "winc j "new "cal LoadOpts() endf fu! FileView() let path=PathUnderCursor() if(isdirectory(path)) return end "cal ProvideBuffer() "exe "edit ".path let s:buffer_to_load=path cal Close() setl noma setl ro endf fu! FileEdit() let path=PathUnderCursor() if(isdirectory(path)) return end "cal ProvideBuffer() "exe "edit ".path let s:buffer_to_load=path cal Close() setl ma setl noro endf fu! NewFileEdit() let path=MyPath() let newfile=PathUnderCursor() if(isdirectory(newfile)) let newfile=path end let newfile=input("File to edit: ", newfile) if newfile=="" return end if(isdirectory(newfile)) echo "Unable to edit file: directory with same name exists" return end "cal ProvideBuffer() "exe "edit ".newfile let s:buffer_to_load=path cal Close() setlocal ma setlocal noro endf fu! MyPath() if exists("s:bufnr_left") if winbufnr(0) == s:bufnr_left return s:path_left."/" else return s:path_right."/" en else if winbufnr(0) == s:bufnr_right return s:path_left."/" else return s:path_right."/" en end endf fu! BuildTreeNoPrev(path) let path=expand(a:path) let oldpath=MyPath() let b:vimcommander_selected="" " clean up setl ma norm! ggVG"_xo " check if no unneeded trailing / is there if strlen(path)>1&&path[strlen(path)-1]=="/" let path=strpart(path,0,strlen(path)-1) en if(winbufnr(0)==s:bufnr_right) let s:path_right=path else let s:path_left=path end if g:vimcommander_shallcd==1 exe "cd ".MyPath() end cal setline(1,path) setl noma nomod " pass -1 as xpos to start at column 0 cal TreeExpand(-1,1,path) " move to first entry norm! ggj4| endf fu! BuildTree(path) let oldpath=MyPath() cal BuildTreeNoPrev(a:path) if oldpath!=GetNextLine(b:vimcommander_prev) let b:vimcommander_prev=oldpath."\n".b:vimcommander_prev end let b:vimcommander_next="" endf fu! RefreshDisplays() let line=line('.') cal BuildTree(MyPath()) exec line norm 4| cal SwitchBuffer() let line=line('.') cal BuildTree(MyPath()) exec line norm 4| cal SwitchBuffer() endf fu! DirCreate() let newdir="" let newdir=input("New directory name: ","") if filereadable(newdir) echo "File with that name exists." return end if isdirectory(newdir) echo "Directory already exists." return end let i=system("mkdir ".MyPath().newdir) cal RefreshDisplays() norm! gg1j cal search("^+".newdir."$") norm! 4| endf fu! OtherPath() if winbufnr(0) == s:bufnr_left return s:path_right."/" else return s:path_left."/" en endf fu! GetLine() let line=getline(line('.')) retu strpart(line, 1) endf fu! FilenameUnderCursor() let path=GetLine() let path=strpart(path, 2) return path endf fu! GetPathName(xpos,ypos) let xpos=a:xpos let ypos=a:ypos " check for directory.. let line=getline(ypos) " check selected let path=FilenameUnderCursor() let path='/'.path " add base path " not needed, if in root if getline(1)!='/' let path=getline(1).path en retu path endf fu! PathUnderCursor() let xpos=2 let ypos=line('.') if ypos>1 "not on line 1 let rv=GetPathName(xpos,ypos) return rv end return "" endf fu! FileCopy() let i=0 if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let otherfilename=OtherPath().name let i=i+1 else let name=" " let filename=PathUnderCursor() let otherfilename=OtherPath().FilenameUnderCursor() end let opt="y" while strlen(name)>0 if filereadable(filename) || isdirectory(filename) if strlen(b:vimcommander_selected)==0 let newfilename=input("Copy ".filename." to: ",otherfilename) else let newfilename=otherfilename end if filereadable(filename) && isdirectory(newfilename) cal RefreshDisplays() echo "Can't overwrite directory ".newfilename." with file" return end if isdirectory(filename) && filereadable(newfilename) cal RefreshDisplays() echo "Can't overwrite file ".newfilename." with directory" return end if filereadable(newfilename) if opt!~"^[AakK]$" let opt=input("File ".newfilename." exists, overwrite? [nkya] ","y") if opt=="" cal RefreshDisplays() return end end if opt=~"^[yYAa]$" " copy file cal system('cp -Rf "'.filename.'" "'.newfilename.'"') en el " copy file cal system('cp -Rf "'.filename.'" "'.newfilename.'"') en en if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let otherfilename=OtherPath().name let i=i+1 else let name="" end endwhile let b:vimcommander_selected="" cal RefreshDisplays() endf fu! FileMove() let i=0 if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let otherfilename=OtherPath().name let i=i+1 else let name=" " let filename=PathUnderCursor() let otherfilename=OtherPath().FilenameUnderCursor() end let opt='y' while strlen(name)>0 if filereadable(filename) || isdirectory(filename) if strlen(b:vimcommander_selected)==0 let newfilename=input("Move ".filename." to: ",otherfilename) else let newfilename=otherfilename end if filereadable(filename) && isdirectory(newfilename) cal RefreshDisplays() echo "Can't overwrite directory with file" return end if isdirectory(filename) && filereadable(newfilename) cal RefreshDisplays() echo "Can't overwrite file with directory" return end if isdirectory(filename) && isdirectory(newfilename) cal RefreshDisplays() echo "Can't overwrite directory with directory" return end if filereadable(newfilename) if opt!~"^[AakK]$" let opt=input("File ".newfilename." exists, overwrite? [nkya] ","y") if opt=="" cal RefreshDisplays() return end end if opt=~"^[yYAa]$" " move file cal system('mv -f "'.filename.'" "'.newfilename.'"') en el " move file cal system('mv "'.filename.'" "'.newfilename.'"') en en if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let otherfilename=OtherPath().name let i=i+1 else let name="" end endwhile let b:vimcommander_selected="" cal RefreshDisplays() endf fu! FileDelete() let i=0 if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let i=i+1 else let name=" " let filename=PathUnderCursor() end let opt="" while strlen(name)>0 if filereadable(filename) || isdirectory(filename) if opt!~"^[AakK]$" let opt=input("OK to delete ".fnamemodify(filename,":t")."? [nkya] ","y") if opt=="" cal RefreshDisplays() return end end if opt=~"^[yYAa]$" cal system('rm -rf "'.filename.'"') en en if strlen(b:vimcommander_selected)>0 let name=SelectedNum(b:vimcommander_selected, i) let filename=MyPath().name let i=i+1 else let name="" end endwhile let b:vimcommander_selected="" cal RefreshDisplays() endf fu! PutDir() if winbufnr(0)==s:bufnr_left let mypath=s:path_left else let mypath=s:path_right end cal SwitchBuffer() cal BuildTree(mypath) cal SwitchBuffer() cal RefreshDisplays() endf fu! GetOrPutDir(dir) if a:dir=='l' && winbufnr(0)==s:bufnr_left " left and left - getdir cal BuildTree(OtherPath()) return end if a:dir=='r' && winbufnr(0)==s:bufnr_right " right and right - getdir cal BuildTree(OtherPath()) return end " Crossed - putdir let path=PathUnderCursor() if !isdirectory(path) return end cal SwitchBuffer() cal BuildTree(path) cal SwitchBuffer() cal RefreshDisplays() endf fu! ExchangeDirs() let pathtmp=s:path_left let s:path_left=s:path_right let s:path_right=pathtmp let myline=line('.') cal BuildTree(MyPath()) cal SwitchBuffer() cal BuildTree(MyPath()) exec myline cal RefreshDisplays() endf fu! GetNextLine(text) let pos=match(a:text,"\n") retu strpart(a:text,0,pos) endf fu! CutFirstLine(text) let pos=match(a:text,"\n") if pos==-1 return "" end retu strpart(a:text,pos+1,strlen(a:text)) endf fu! SelectedNum(str,idx) let mystr=a:str let i=0 wh iCutFirstLine(mystr) let i=i+1 endwh let pos=stridx(mystr, "\n") if pos!=-1 let mystr=strpart(mystr, 0, pos) end return mystr endf fu! IsSelected(line) let rv=(a:line=~"^>.*") retu rv endf fu! Select() let name=GetLine() if IsSelected(name) let name=FilenameUnderCursor() let tmp="" let found=SelectedNum(b:vimcommander_selected, 0) let i=1 while found!="" if found!=name let tmp=tmp.found."\n" end let found=SelectedNum(b:vimcommander_selected, i) let i=i+1 endwhile let b:vimcommander_selected=tmp setl ma norm! |l norm! s setl noma cal GotoNextEntry() else " select let b:vimcommander_selected=b:vimcommander_selected.FilenameUnderCursor()."\n" setl ma norm! | norm! l norm! s> setl noma cal GotoNextEntry() end endf fu! SelectPattern(pattern) let origdirlist='' let path=MyPath() if s:show_hidden_files let dirlistorig=glob(path.'/.*'.a:pattern)."\n" en let origdirlist=origdirlist.globpath(path, a:pattern)."\n" let myline=line('.') norm! G let lastline=line('.') norm! gg norm! j while line('.')GetLine() if(! (IsSelected(line))) wh strlen(dirlist)>0 " get next line let entry=GetNextLine(dirlist) let dirlist=CutFirstLine(dirlist) " only files if entry!="." && entry!=".." && entry!="" if entry==PathUnderCursor() cal Select() norm! k let dirlist="" continue end en endw end norm! j endwhile cal GotoEntry(myline) endf fu! DeSelectPattern(pattern) let origdirlist='' let path=MyPath() if s:show_hidden_files let dirlistorig=glob(path.'/.*'.a:pattern)."\n" en let origdirlist=origdirlist.globpath(path, a:pattern)."\n" let myline=line('.') norm! G let lastline=line('.') norm! gg norm! j while line('.')GetLine() if IsSelected(path) let path=MyPath().FilenameUnderCursor() wh strlen(dirlist)>0 " get next line let entry=GetNextLine(dirlist) let dirlist=CutFirstLine(dirlist) " only files if entry!="." && entry!=".." && entry!="" "echo "cursor in ".path." entry ".entry." len ".strlen(dirlist) if entry==path cal Select() norm! k let dirlist="" continue end end endw end norm! j endwhile cal GotoEntry(myline) endf fu! SelectPatternAsk() let pattern=input("Select with pattern: ") cal SelectPattern(pattern) echo "" endf fu! DeSelectPatternAsk() let pattern=input("Deselect with pattern: ") cal DeSelectPattern(pattern) echo "" endf fu! GotoNextEntry() let xpos=col('.') " different movement in line 1 if line('.')==1 " if over slash, move one to right if getline('.')[xpos-1]=='/' norm! l " only root path there, move down if col('.')==1 norm! j4 en el " otherwise after next slash norm! f/l " if already last path, move down if col('.')==xpos norm! j4 en en el norm! j4| en endf fu! GotoPrevEntry() " different movement in line 1 if line('.')==1 " move after prev slash norm! hF/l el " enter line 1 at the end if line('.')==2 norm! k$F/l el norm! k4| en en endf fu! PrevDir() let newpath=GetNextLine(b:vimcommander_prev) let oldpath=MyPath() let b:vimcommander_prev=CutFirstLine(b:vimcommander_prev) if strlen(newpath)>0 cal BuildTreeNoPrev(newpath) if oldpath!=GetNextLine(b:vimcommander_next) let b:vimcommander_next=oldpath."\n".b:vimcommander_next end end endf fu! NextDir() let newpath=GetNextLine(b:vimcommander_next) let oldpath=MyPath() let b:vimcommander_next=CutFirstLine(b:vimcommander_next) if strlen(newpath)>0 cal BuildTreeNoPrev(newpath) if oldpath!=GetNextLine(b:vimcommander_prev) let b:vimcommander_prev=oldpath."\n".b:vimcommander_prev end end endf fu! ShowHiddenFilesToggle() if (s:show_hidden_files==0) let s:show_hidden_files=1 el let s:show_hidden_files=0 en cal RefreshDisplays() endf "== From Opsplorer: ========================================================== fu! InitOptions() let s:single_click_to_edit=0 let s:file_match_pattern="*" "let s:file_match_pattern="\"`ls -d * | egrep -v \"(\.d$|\.o$|^tags$)\";ls config.mk`\"" let s:show_hidden_files=0 let s:split_vertical=1 let s:split_width=20 let s:split_minwidth=1 let s:use_colors=1 let s:close_explorer_after_open=0 endf fu! InsertFilename() norm! 4| let filename=GetPathName(col('.')-1,line('.')) winc p exe "norm! a".filename endf fu! InsertFileContent() norm! 4| let filename=GetPathName(col('.')-1,line('.')) if filereadable(filename) winc p exe "r ".filename en endf fu! FileSee() norm! 4| let filename=GetPathName(col('.')-1,line('.')) if filereadable(filename) let i=system("see ".filename."&") en endf fu! BuildParentTree() norm! gg$F/ let mydir=getline(line('.')) let mypos="^..+".strpart(mydir, strridx(mydir,'/')+1)."$" cal OnDoubleClick() call search(mypos) norm! 4| endf fu! GotoNextNode() " in line 1 like next entry if line('.')==1 cal GotoNextEntry() el norm! j4| wh getline('.')[col('.')-1] !~ "[+-]" && line('.')GotoPrevNode() " entering base path section? if line('.')<3 cal GotoPrevEntry() el norm! k4| wh getline('.')[col('.')-1] !~ "[+-]" && line('.')>1 norm! k4| endw en endf fu! OnClick() let xpos=col('.')-1 let ypos=line('.') if s:single_click_to_edit cal OnDoubleClick() en endf fu! OnDoubleClick() let xpos=col('.')-1 let ypos=line('.') " go to first non-blank when line>1 if ypos>1 let xpos=2 " check, if it's a directory let path=GetPathName(xpos,ypos) if isdirectory(path) " build new root structure cal BuildTree(path) el " try to resolve filename " and open in other window if filereadable(path) cal FileEdit() en en el " we're on line 1 here! getting new base path now... " advance to next slash if getline(1)[xpos]!="/" norm! f/ " no next slash -> current directory, just rebuild if col('.')-1==xpos cal BuildTree(getline(1)) retu en en " cut ending slash norm! h " rebuild tree with new path cal BuildTree(strpart(getline(1),0,col('.'))) en endf fu! TreeExpand(xpos,ypos,path) let path=a:path setl ma " first get all subdirectories let dirlist="" " extra globbing for hidden files if s:show_hidden_files let dirlist=glob(path.'/.*')."\n" en " add norm! entries let dirlist=dirlist.glob(path.'/*')."\n" " remember where to append let row=a:ypos wh strlen(dirlist)>0 " get next line let entry=GetNextLine(dirlist) let dirlist=CutFirstLine(dirlist) " add to tree if directory if isdirectory(entry) let entry=substitute(entry,".*/",'','') if entry!="." && entry!=".." " indent, mark as node and append let entry=" "."+".entry cal append(row,entry) let row=row+1 en en endw " now get files let dirlist="" " extra globbing for hidden files if s:show_hidden_files let dirlist=glob(path.'/.*'.s:file_match_pattern)."\n" en let dirlist=dirlist.globpath(path, s:file_match_pattern)."\n" wh strlen(dirlist)>0 " get next line let entry=GetNextLine(dirlist) let dirlist=CutFirstLine(dirlist) " only files if entry!="." && entry!=".." && entry!="" if !isdirectory(entry)&&filereadable(entry) let entry=substitute(entry,".*/",'','') " indent and append let entry=" ".entry cal append(row,entry) let row=row+1 en en endw setl noma nomod endf fu! ToggleShowHidden() let s:show_hidden_files = 1-s:show_hidden_files cal BuildTree(getline(1)) endf fu! SetMatchPattern() let s:file_match_pattern=input("Match pattern: ",s:file_match_pattern) cal BuildTree(getline(1)) endf fu! SpellInstallDocumentation(full_name, revision) " Name of the document path based on the system we use: if (has("unix")) " On UNIX like system, using forward slash: let l:slash_char = '/' let l:mkdir_cmd = ':silent !mkdir -p ' else " On M$ system, use backslash. Also mkdir syntax is different. " This should only work on W2K and up. let l:slash_char = '\' let l:mkdir_cmd = ':silent !mkdir ' endif let l:doc_path = l:slash_char . 'doc' let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc' " Figure out document path based on full name of this script: let l:vim_plugin_path = fnamemodify(a:full_name, ':h') let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path if (!(filewritable(l:vim_doc_path) == 2)) echomsg "Doc path: " . l:vim_doc_path execute l:mkdir_cmd . l:vim_doc_path if (!(filewritable(l:vim_doc_path) == 2)) " Try a default configuration in user home: let l:vim_doc_path = expand("~") . l:doc_home if (!(filewritable(l:vim_doc_path) == 2)) execute l:mkdir_cmd . l:vim_doc_path if (!(filewritable(l:vim_doc_path) == 2)) " Put a warning: echomsg "Unable to open documentation directory" echomsg " type :help add-local-help for more informations." return 0 endif endif endif endif " Exit if we have problem to access the document directory: if (!isdirectory(l:vim_plugin_path) \ || !isdirectory(l:vim_doc_path) \ || filewritable(l:vim_doc_path) != 2) return 0 endif " Full name of script and documentation file: let l:script_name = fnamemodify(a:full_name, ':t') let l:doc_name = fnamemodify(a:full_name, ':t:r') . '.txt' let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name " Bail out if document file is still up to date: if (filereadable(l:doc_file) && \ getftime(l:plugin_file) < getftime(l:doc_file)) return 0 endif " Prepare window position restoring command: if (strlen(@%)) let l:go_back = 'b ' . bufnr("%") else let l:go_back = 'enew!' endif " Create a new buffer & read in the plugin file (me): setl nomodeline exe 'enew!' exe 'r ' . l:plugin_file setl modeline let l:buf = bufnr("%") setl noswapfile modifiable norm! zR norm! gg " Delete from first line to a line starts with " === START_DOC 1,/^=\{3,}\s\+START_DOC\C/ d " Delete from a line starts with " === END_DOC " to the end of the documents: /^=\{3,}\s\+END_DOC\C/,$ d " Remove fold marks: % s/{\{3}[1-9]/ / " Add modeline for help doc: the modeline string is mangled intentionally " to avoid it be recognized by VIM: call append(line('$'), '') call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:') " Replace revision: exe "norm! :1s/#version#/ v" . a:revision . "/\" " Save the help document: exe 'w! ' . l:doc_file exe l:go_back exe 'bw ' . l:buf " Build help tags: exe 'helptags ' . l:vim_doc_path return 1 endf if exists("b:vimcommander_install_doc") && b:vimcommander_install_doc==0 finish end let s:revision= \ substitute("$Revision: 1.54.2.2 $",'\$\S*: \([.0-9]\+\) \$','\1','') silent! let s:install_status = \ SpellInstallDocumentation(expand(':p'), s:revision) if (s:install_status == 1) echom expand(":t:r") . ' v' . s:revision . \ ': Help-documentation installed.' endif finish """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Section: Documentation Contents """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" === START_DOC *vimcommander.txt* total-commander-like file-manager for vim. #version# VIMCOMMANDER REFERENCE MANUAL~ File-manager for vim. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License. See http://www.gnu.org/copyleft/gpl.txt ============================================================================== CONTENT *vimcommander-contents* Installation : |vimcommander-install| Intro : |vimcommander| Keys : |vimcommander-keys| Todo list : |vimcommander-todo| Links : |vimcommander-links| ============================================================================== 1. VimCommander Installation *vimcommander-install* In order to install the plugin, place the vimcommander.vim file into a plugin directory in your runtime path (please see |add-global-plugin| and |'runtimepath'|). A key-map should also be made. Put in your |.vimrc| something like: > noremap :cal VimCommanderToggle() < ============================================================================== 2. VimCommander Intro *vimcommander* This is VimCommander, a two-panel file-manager for vim. Upon entrance, the two panels are presented. Operations are performed by default from one panel to the other. File selection is implemented also, see |vimcommander-keys| for the keyboard shortcuts. See also |vimcommander-links| for more information on this kind of file-manager. 2.1 List of Features: *vimcommander-features* --------------------- - Two panels side-by-side; - File operations work only on unix; - File selection; - Remembers settings; - Directory history. ============================================================================== 3. VimCommander Options *vimcommander-opts* This are the options that can be set from the user's .vimrc, just use: > let g: