vim-relatively-complete

Vim plugin to complete files relative to the current file, unless path explicitly specified.
git clone git://git.alex.balgavy.eu/vim-relatively-complete.git
Log | Files | Refs | README | LICENSE

relative_file_complete.vim (942B)


      1 if exists('g:loaded_relatively_complete_autoload')
      2   finish
      3 endif
      4 let g:loaded_relatively_complete_autoload = 1
      5 
      6 " Save cwd, cd to dir enclosing file, then go back to saved dir when complete done
      7 function! relative_file_complete#SaveAndRestoreOnComplete()
      8   " Save the old cwd
      9   let s:olddir = getcwd()
     10 
     11   " Locally switch to the dir enclosing current file
     12   lcd %:p:h
     13 
     14   " Defer changing cwd back until complete is done
     15   augroup relative_file_complete_reset_cwd
     16     au!
     17     au CompleteDone <buffer> call relative_file_complete#Cleanup()
     18   augroup END
     19 endfunction
     20 
     21 " When complete finishes, need to change cwd back and clear autocmd
     22 function! relative_file_complete#Cleanup()
     23   " Go back to the previous dir and remove the saved variable
     24   exe "lcd ".s:olddir
     25   unlet s:olddir
     26 
     27   " Clear the cleanup autocmd and augroup
     28   augroup relative_file_complete_reset_cwd
     29     au!
     30   augroup END
     31   augroup! relative_file_complete_reset_cwd
     32 endfunction