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

commit fa1f8d9f731bbb9dcf129aae6fb7752dc004e9a3
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sat, 29 Feb 2020 01:38:31 +0100

Initial commit

Diffstat:
A.gitignore | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautoload/relative_file_complete.vim | 27+++++++++++++++++++++++++++
Aplugin/relative_file_complete.vim | 2++
3 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,58 @@ + +# Created by https://www.gitignore.io/api/macos,vim +# Edit at https://www.gitignore.io/?templates=macos,vim + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +# End of https://www.gitignore.io/api/macos,vim diff --git a/autoload/relative_file_complete.vim b/autoload/relative_file_complete.vim @@ -0,0 +1,27 @@ +" Save cwd, cd to dir enclosing file, then go back to saved dir when complete done +function! relative_file_complete#SaveAndRestoreOnComplete() + " Save the old cwd + let s:olddir = getcwd() + + " Locally switch to the dir enclosing current file + lcd %:p:h + + " Defer changing cwd back until complete is done + augroup relative_file_complete_reset_cwd + au! + au CompleteDone <buffer> call relative_file_complete#Cleanup() + augroup END +endfunction + +" When complete finishes, need to change cwd back and clear autocmd +function! relative_file_complete#Cleanup() + " Go back to the previous dir and remove the saved variable + exe "lcd ".s:olddir + unlet s:olddir + + " Clear the cleanup autocmd and augroup + augroup relative_file_complete_reset_cwd + au! + augroup END + augroup! relative_file_complete_reset_cwd +endfunction diff --git a/plugin/relative_file_complete.vim b/plugin/relative_file_complete.vim @@ -0,0 +1,2 @@ +command! CompleteRelative :call relative_file_complete#SaveAndRestoreOnComplete() +inoremap <Plug>CompleteRelative <c-o>:CompleteRelative<CR><C-x><C-f>