현재 파일의 전체 경로를 확장하여 Vim의 명령에 전달하려면 어떻게해야합니까?
명령 모드로 이동하여 입력하면
:!mycommand %
현재 파일에서 명령을 실행합니다 ( %
현재 파일 이름으로 확장). 전체 파일 이름을 전체 경로로 확장하는 유사한 구성이 있습니까?
Windows를 사용하고 있습니다.
:!mycommand %:p
관련 :
:!cd %:p:h
다른 두 가지 대답은 (어떤 이유로 든) 나를 위해 작동하지 않았습니다. 그러나 일반 모드로 입력하면이 콤보에 전체 경로가 표시됩니다.
그런 1다음CtrlG
출처 : Vim Tips Wiki의“ 현재 파일 이름 가져 오기” 의 {count}CTRL-G
섹션 도 참조하십시오 :help CTRL-G
.
추가 :p
, 예 :
:!mycommand %:p
그리고 %:p:h
당신에게 파일이 상주하는 디렉토리의 경로를 제공 할 것입니다.
현재 vim 파일 이름을 인쇄하려면 :
:help expand
:echo expand("%:p") " absolute path
:echo expand("%:p:h") " absolute path dirname
:echo expand("%:p:h:h")" absolute path dirname dirname
:echo expand("%:.") " relative path
:echo expand("%:.:h") " relative path dirname
:echo expand("%:.:h:h")" relative path dirname dirname
:echo expand("<sfile>:p") " absolute path to [this] vimscript
:help filename-modifiers
(a VIM 기능 포함) 예를 들어 행 resolve()
과 expand()
현재 스크립트 절대 경로에 대한 심볼 링크 <sfile>:p
(대신 %:p
) 다음 exec
에 -ed 파일명 함수 VIM 로컬 변수를 포함 :source
fnameescape
l:vimrcfilename
" g:__sfile__dirname -- directory containing this vimrc script
" after symlinks
" ~dirname(abspath(realpath(__file__)))
let g:__sfile__dirname=fnamemodify(resolve(expand("<sfile>:p")), ":h")
" Source_dotvim(filename) -- source dirname(this_vimrc)/filename
function Source_dotvim(filename)
let l:vimrcfilename=g:__sfile__dirname . "/" . a:filename
if filereadable(l:vimrcfilename) && !empty(l:vimrcfilename)
"source s:vimrcfilename "this doesn't work, so exec:
exec "source " . fnameescape(l:vimrcfilename)
else
echo l:vimrcfilename . " empty or not found."
endif
endfunction
call Source_dotvim("vimrc.local.01-env.vimrc")
노트:
:help fnamemodify
- "현재 파일":
%:p
(버퍼 파일) /<sfile>:p
(스크립트 파일) expand('<sfile>')
함수 내에서 작동하지 않습니다- 소스
l:varname
가 작동하지 않습니다. 따라서exec
-문자열 연결-및fnameescape
:messages
가장 최근의 200 vim [오류,] 메시지를 인쇄합니다
참고 문헌
현재 파일의 이름을 얻습니다. http://vim.wikia.com/wiki/Get_the_name_of_the_current_file
Set_working_directory_to_the_current_file http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
If you want to use the full path in your vimrc
, you can use something like this:
let vimFiles = '$HOME/.vim'
let absPath = expand(vimFiles . '/subDir')
This will give you a path with backslashes on Windows.
'Programming' 카테고리의 다른 글
공유 객체에서 모든 심볼을 내보내는 방법은 무엇입니까? (0) | 2020.07.12 |
---|---|
ASP.NET MVC 5 및 WEB API 2에서 oauth2 서버를 구현하는 방법 (0) | 2020.07.12 |
미디어 쿼리-두 너비 사이 (0) | 2020.07.12 |
JSON 배열을 통한 JavaScript 루프? (0) | 2020.07.12 |
Django 모델 양식 객체의 자동 생성 날짜? (0) | 2020.07.12 |