In Vim, when I am in insert mode, and I want to use file-name completion, I want the search path to be relative to the current file, not the current working directory. For instance, if in insert mode I type the following:
I plan on extracting it out into a function and setting a variable for the pwd before the lcs command is issued and then resetting it at some point in time. It would be nice if there was a menu autocmd.
I may or may not use this, but I thought I would throw out another solution.
" [relative autocomplete]
" Vim's file autocomplete (C-X C-F) works only in an absolute path (using the
" current working directory) as base. But in most languages, you want to use
" relative imports, and file autocomplete doesn't work there. For that, I use
function! s:EnableRelativeAutocomplete() abort
let b:relative_autocomplete_cleanup_pending = 1
function! s:DisableRelativeAutocomplete() abort
if exists('b:relative_autocomplete_cleanup_pending') && b:relative_autocomplete_cleanup_pending
let b:relative_autocomplete_cleanup_pending = 0
inoremap <C-x><C-x><C-f> <C-o>:call <SID>EnableRelativeAutocomplete()<CR><C-x><C-f>
autocmd InsertLeave * call s:DisableRelativeAutocomplete()
It will change the working directory to the current file's when using <C-x><C-x><C-f> and back to the previous directory when leaving insert mode, if needed.