2013-03-27 3 views
1

검색을 완료하면 출력 메시지를 변경하고 싶습니다.검색의 출력 메시지를 변경하는 방법은 무엇입니까?

p.e. 매우 긴 정규식으로 검색 할 때 아무 것도 발견되지 않을 때 vim이 메시지를 반환합니다. E486: Pattern not found: .... very long regex code ...

출력을 캡처하고이 메시지를 변경하고 싶습니다. 어떻게해야합니까?

+0

에 당신이 내 질문을 downvote 당신이 그것을 downvote 이유를 말해 경우 이름을 적어주세요 기능에 try/catch을 포장 할 수있다. tnx. – Reman

답변

4

:s[ubstitute] 명령은 오류를 표시하지 않기 위해 /e 플래그가 있지만 AFAIK도 :silent /foo이라도 오류 메시지가 표시되지 않습니다. 글쎄, 당신은 그것을 억압하고 싶지 않습니다, 어쨌든, 당신은 그것을 "포착"하고 다른 것을 보여주고 싶습니다.

모든 언어와 마찬가지로 vimscript에는 try/catch이 있습니다. 당신은 :h :try에서 그것을 읽을 수 있습니다.

try 
    /foo 
catch /^Vim\%((\a\+)\)\=:E486/ 
    let @n = v:exception 
    echo "No luck!" 
endtry 

당신은 당신이 noremap/

+0

감사합니다. Romainl, catch의 내용을 클립 보드 (또는 레지스터)에 저장하는 방법을 알고 있습니까? – Reman

+0

'v : exception'을 사용하십시오. 내 대답을 업데이트했습니다. – romainl

+0

대단히 감사합니다! :) – Reman

2

나는 당신이 vimscript에서 오류 메시지를 잡는 것에 대해 이야기하고 있다고 생각합니다.

그럼 당신은 catch을 체크 아웃 할 수 있습니다 : 검색을 할 :h catch

    *:cat* *:catch* *E603* *E604* *E605* 
:cat[ch] /{pattern}/ The following commands until the next |:catch|, 
      |:finally|, or |:endtry| that belongs to the same 
      |:try| as the ":catch" are executed when an exception 
      matching {pattern} is being thrown and has not yet 
      been caught by a previous ":catch". Otherwise, these 
      commands are skipped. 
      When {pattern} is omitted all errors are caught. 
      Examples: > 
     :catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C) 
     :catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors 
     :catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts 
     :catch /^Vim(write):/  " catch all errors in :write 
     :catch /^Vim\%((\a\+)\)\=:E123/ " catch error E123 
     :catch /my-exception/  " catch user exception 
     :catch /.*/   " catch everything 
     :catch    " same as /.*/ 

블록 try에 다음 오류 메시지를 잡을 수 있고, 당신이 원하는 무엇이든 할.

관련 문제