答え1
もし、あんたが
:set autochdir
希望する動作が得られます。ただし、作業ディレクトリを保持する必要がある場合 (他のプロジェクト ファイルを簡単に開くためなど)、autocmds を使用して CWD を保存/復元する必要があります。
:autocmd InsertEnter * let save_cwd = getcwd() | set autochdir
:autocmd InsertLeave * set noautochdir | execute 'cd' fnameescape(save_cwd)
答え2
答え3
私のにはこれがあります.vimrc
:
" [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
" <C-X><C-X><C-F>:
function! s:EnableRelativeAutocomplete() abort
let b:relative_autocomplete_cleanup_pending = 1
lcd %:p:h
endfunction
function! s:DisableRelativeAutocomplete() abort
if exists('b:relative_autocomplete_cleanup_pending') && b:relative_autocomplete_cleanup_pending
lcd -
let b:relative_autocomplete_cleanup_pending = 0
endif
endfunction
inoremap <C-x><C-x><C-f> <C-o>:call <SID>EnableRelativeAutocomplete()<CR><C-x><C-f>
augroup relative_file_autocomplete
autocmd!
autocmd InsertLeave * call s:DisableRelativeAutocomplete()
augroup END
必要に応じて、使用時に作業ディレクトリを現在のファイルのディレクトリに変更し<C-x><C-x><C-f>
、挿入モードを終了するときに前のディレクトリに戻します。