2017-09-30 1 views
0

사용자가 태그로 이동하려고 다음과 같은 명령을 사용하는 경우 :빔 스크립트 캡처 번호 사용자 입력에 "유형 번호와 <Enter> (빈 CANCEL (취소)) :"예를 들어

:tjump "some_function" 

빔 것 가능한 태그 일치 목록을 보여줍니다. 사용자가 입력 한 내용을 '캡처'할 수있는 방법이 있습니까? 함수에서

예 :

function! GoToTag() 
    let l:search_tag = expand('<cword>')  " this will capture the word under the cursor 
    exe 'tjump' l:search_tag 
    """" capture the number the user puts in 

내 목표는 사용자가 선택한하지만 존재하지 않는 경우, 저장소에서 해당 파일을 체크 아웃로 이동 한 다음 파일로 이동 할 수있다 그것. 자동으로 번호를 다시 증명하는 사용자 입력이 어려운 것을 요청없이 체크 아웃 후 파일에가는 :

function! GoToTag() 
    try 
     let l:search_tag = expand('<cword>') " Get the word under the cursor 
     exe 'tjump' l:search_tag    " go to tag, list options if tag is in multiple locations 
    catch /^Vim(tjump):E429:/     " catch the missing file error if file doesn't exist (not synced) 
     """ sync the file the user wanted to jump to using whatever repository command applies to you 
     """ go to that file and line corresponding to the user's original choice 
    entry 
endfunction 
+0

자세한 배경을 알려주십시오; 최종 목표는 무엇입니까? 질문이 기술적 인 단계에 불과할 때 좋은 대답을 제시하기가 어렵습니다. 우리에게 ** ** 당신이 이것을 원하면 ** [XY 문제] (http://meta.stackoverflow.com/questions/66377/what-is-the-xy-problem)에 굴복하기가 쉽지 않은 이유를 말해주십시오.). –

+0

@IngoKarkat 궁극적 인 목표를 제공하기 위해 원래 질문을 업데이트했습니다. 나는 기본적으로 내 코드베이스를 인덱싱하는 태그 파일을 가지고 있으며 전체 코드베이스를 체크 아웃하지 않고보고자하는 파일을 선택적으로 체크 아웃하려고합니다. – supernun

답변

0

아니, 당신은 단지 (태그에 점프의) 효과를 관찰 할 수있다, 또는 중단 사용자 선택, 출력 캡처 및 에코 및 쿼리 직접 구현 : 예 :

let search_tag = expand('<cword>') 
redir => commandOutput 
    silent! execute 'tjump' search_tag 
redir END 
echo substitute(commandOutput, '\n[^\n]*$', '', '') " Remove last query line; we'll duplicate that with input(). 
let answer = input('Type number and <Enter>: ')