답변1
만약 너라면
:set autochdir
당신은 당신이 원하는 행동을 얻을 것입니다. 그러나 작업 디렉토리를 유지해야 하는 경우(예: 다른 프로젝트 파일을 쉽게 열기 위해) autocmds를 사용하여 CWD를 저장/복원해야 합니다.
:autocmd InsertEnter * let save_cwd = getcwd() | set autochdir
:autocmd InsertLeave * set noautochdir | execute 'cd' fnameescape(save_cwd)
답변2
@잉고 카르캣'에스답변좋은데 넣기가 좀 꺼려지네요내 vimrc, 왜냐하면 심지어도움말 페이지'autochdir'
사용하면 일부 플러그인이 중단된다는 메모를 제공합니다.
나는 내 사용 사례에 매우 적합한 나만의 솔루션을 생각해 냈습니다.
나는 그것을 함수로 추출하고 lcs 명령이 실행되기 전에 pwd에 대한 변수를 설정한 다음 특정 시점에 재설정할 계획입니다. autocmd 메뉴가 있으면 좋을 것 같습니다.
이것을 사용할 수도 있고 사용하지 않을 수도 있지만 다른 솔루션을 버릴 것이라고 생각했습니다.
답변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>
하고 삽입 모드를 종료할 때 이전 디렉터리로 돌아갑니다.