2017-01-30 3 views
0

내 노트의 구문 정의를 만들려고합니다.파일의 첫 줄에 Vim 구문 영역이 있습니다

=Title of the note (it's the very first line) 
@context (mandatory) 
!action (mandatory) 
#tag-1 (optional) 
#tag-2 (optional) 
#tag-n (optional) 
>attached-files (optional) 

My note come after the first blank line 
and continue until the end of the file... 

No matter any additional empty line 

그때 강조 구문을 만들고 싶습니다가 differents의 경기를 논제 : 다음

은 예입니다. 필자는 제목 (= this way)이나 태그 (this-way)처럼 보이는 줄을 쓸 수 있으며 강조 표시 할 필요가 없다. 첫 번째 줄부터 첫 번째 빈 줄까지 노트 메타 데이터를위한 영역을 만들려고합니다.

나는이 시도하지만 난 문제 (강조는 좋은 것 같지만있어 나는 빈 줄 결국 라인 (빈 라인 포함) 후 더 이상 작동하지 않습니다 ...

augroup gtd 

    autocmd! 

    autocmd BufRead,BufNewFile *.gtd set filetype=gtd 

    autocmd FileType gtd syntax region gtdTags start="\%1l" end="^\s*$" fold transparent contains=gtdTitle,gtdContext,gtdStatus,gtdHashtags,gtdAttachedFiles 
    autocmd FileType gtd syntax match gtdTitle '^=.*' contained 
    autocmd FileType gtd syntax match gtdContext '^@\S\+$' contained 
    autocmd FileType gtd syntax match gtdStatus '^!\S\+$' contained 
    autocmd FileType gtd syntax match gtdHashtags '^#\S\+$' contained 
    autocmd FileType gtd syntax match gtdAttachedFiles '^>attached-files$' contained 

    autocmd FileType gtd syntax match gtdSubtitle '^\s*\*\* .*' 
    autocmd FileType gtd syntax keyword gtdTodo TODO WAITING SOMEDAY SCHEDULED 

    autocmd FileType gtd highlight gtdTitle guifg=white guibg=NONE gui=bold 
    autocmd FileType gtd highlight gtdContext guifg=yellow 
    autocmd FileType gtd highlight gtdStatus guifg=red gui=NONE 
    autocmd FileType gtd highlight gtdHashtags guifg=grey gui=italic 
    autocmd FileType gtd highlight gtdAttachedFiles guifg=red guibg=white gui=bold 

    autocmd FileType gtd highlight gtdSubtitle guifg=black guibg=lightgrey gui=bold 
    autocmd FileType gtd highlight gtdTodo guifg=white guibg=red gui=NONE 

augroup END 

을 삭제하는 경우 첫 번째 빈/빈 줄 또는 파일 끝 부분에서 영역을 중지하는 방법

답변

2

파일 끝 부분을 나타내는 특수 원자를 영역 끝의 패턴에 포함시킬 수 있습니다 : end="^\s*$\|\@$" 그러나 이럴 필요는 없습니다 .Vim 항상은 구문 영역을 시작합니다 whe n start 패턴 일치;

참고 : 만 패턴을 시작 일치를 기반으로 영역을 시작하는 결정을 :help syn-region이 설명으로는 end 패턴을 확인하지 않습니다. 일치하는 끝 패턴 검사가 없습니다.

end 패턴과 일치하는 것이 없더라도 모든 영역은 암시 적으로 버퍼의 끝에서 끝납니다. 사실, 당신의 문법은 제게 잘 작동합니다.

올바른 구문 스크립트를 정의하지 않았고 대신 접두사 autocmd FileType gtd을 선택했기 때문에 혼란 스럽다고 생각합니다. 또한 syntax clear이 없습니다.

:syntax 명령을 ~/.vim/syntax/gtd.vim의 별도 파일에 넣고 :help 44.12에 설명 된 형식을 따르십시오. Vim과 함께 제공되는 $VIMRUNTIME/syntax/*.vim에있는 다양한 구문 스크립트 중 하나를 살펴볼 수도 있습니다.

관련 문제