Programming

현재 파일의 전체 경로를 확장하여 Vim의 명령에 전달하려면 어떻게해야합니까?

procodes 2020. 7. 12. 10:42
반응형

현재 파일의 전체 경로를 확장하여 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 로컬 변수를 포함 :sourcefnameescapel: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")

노트:

참고 문헌


현재 파일의 이름을 얻습니다. 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.

참고URL : https://stackoverflow.com/questions/2233905/how-can-i-expand-the-full-path-of-the-current-file-to-pass-to-a-command-in-vim

반응형