문제
Vim에서 C 전 처리기를 접을 수 있습니까? 예를 들어:
#if defined(DEBUG)
//some block of code
myfunction();
#endif
나는 그것을 접을 수 있도록 그것을 접고 싶다 :
+-- 4 lines: #if defined(DEBUG)---
해결책
이것은 VIM의 강조 엔진의 한계로 인해 사소하지 않습니다. 중첩 영역을 잘 강조 표시 할 수 없습니다. 내가 볼 수 있듯이 두 가지 옵션이 있습니다.
구문 하이라이트를 사용하십시오
contains=
옵션이 작동 할 때까지 옵션 (일부 플러그인에 따라 다름) : :syn region cMyFold start="#if" end="#end" transparent fold contains=ALL " OR syn region cMyFold start="#if" end="#end" transparent fold contains=ALLBUT,cCppSkip " OR something else along those lines " Use syntax folding set foldmethod=syntax
이것은 아마도 많은 혼란이 필요할 것이며 당신은 그것을 만족스럽게 작동하지 않을 수 있습니다. 이것을 넣으십시오
vimfiles/after/syntax/c.vim
또는~/.vim/after/syntax/c.vim
.주름 마커를 사용하십시오. 이것은 효과가 있지만 버팀대 나 원하는 것을 접을 수는 없습니다. 이것을 넣으십시오
~/.vim/after/ftplugin/c.vim
(또는 Windows의 동등한 vimfiles 경로) :" This function customises what is displayed on the folded line: set foldtext=MyFoldText() function! MyFoldText() let line = getline(v:foldstart) let linecount = v:foldend + 1 - v:foldstart let plural = "" if linecount != 1 let plural = "s" endif let foldtext = printf(" +%s %d line%s: %s", v:folddashes, linecount, plural, line) return foldtext endfunction " This is the line that works the magic set foldmarker=#if,#endif set foldmethod=marker
다른 팁
C.VIM 구문 파일 에이 줄을 추가하여 좋아하는 작업을 수행 할 수있었습니다.
syn match cPreConditMatch display "^\s*\zs\(%:\|#\)\s*\(else\|endif\)\>"
+syn region cCppIfAnyWrapper start="^\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\s\+.*\s*\($\|//\|/\*\|&\)" end="^\s*\(%:\|#\)\s*endif\>" contains=TOP,cCppInIfAny,cCppInElseAny fold
+syn region cCppInIfAny start="^\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\s\+.*\s*\($\|//\|/\*\|&\)" end="^\s*\(%:\|#\)\s*\(else\s*\|elif\s\+\|endif\)\>"me=s-1 containedin=cCppIfAnyWrapper contains=TOP
+syn region cCppInElseAny start="^\s*\(%:\|#\)\s*\(else\|elif\)" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 containedin=cCppIfAnyWrapper contains=TOP
if !exists("c_no_if0")
제휴하지 않습니다 StackOverflow