hilight blocks
Is there any simple way to have custom blocks of code highlighted and the remaining code outside the blocks not highlighted? For example: # file.txt some plain text [my-custom-tag] some custom text [/my-custom-tag] Some more plain text ... # end of file So the idea would be to open VIM using file.txt and the code inside the custom tags would be highlighted. Thanks, K
Re: hilight blocks
On 4/12/07, Kirk [EMAIL PROTECTED] wrote: Is there any simple way to have custom blocks of code highlighted and the remaining code outside the blocks not highlighted? For example: # file.txt some plain text [my-custom-tag] some custom text [/my-custom-tag] Some more plain text ... # end of file So the idea would be to open VIM using file.txt and the code inside the custom tags would be highlighted. I've been working something very similar for highlighting code examples in vim helpfiles. As an example: = Begin Example Block: MyExample let s:myvar = testing call myfunc(an arg) Text that shouldn't get highlighted. = End Example = --- Begin Code - syn include @VimL syntax/vim.vim syn match blocktestPrefix /^Block:/ contained nextgroup=blocktestDesc syn match blocktestDesc /\(Block:\)\@=.*$/ contained syn region blocktestText contains=blocktestPrefix,blocktestDesc,blocktestBody,@VimL start=/^Block:.*$\n^\s\+/me=s+1 end=/^\S/me=s-1 Highlight Linking hi def link blocktestPrefix Todo hi def link blocktestDesc PreProc hi def link blocktestBody Label hi def link blocktestComment Comment -- End Code - I found |syntax.txt| and |usr_44.txt| to be helpful. -- Ian Tegebo
Re: hilight blocks
On 2007-04-12, Kirk [EMAIL PROTECTED] wrote: Is there any simple way to have custom blocks of code highlighted and the remaining code outside the blocks not highlighted? For example: # file.txt some plain text [my-custom-tag] some custom text [/my-custom-tag] Some more plain text ... # end of file So the idea would be to open VIM using file.txt and the code inside the custom tags would be highlighted. How about this? match Todo '\[my-custom-tag]\zs\_.\{-}\ze\[/my-custom-tag]' where you can certainly choose some highlight group other than Todo. You can put that line just as it is into your .vimrc, or put it in an after/ftplugin/txt.vim file, or create an autocommand to invoke it on just the files you want. HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Mobile Broadband Division | Spokane, Washington, USA
RE: hilight blocks
I like this one, I put it in my local ~/.vimrc file and it works for VIM (v6.1.3). But when I load this on another machine running VIM (v6.3) I get this error: bash-2.05$ vi file Error detected while processing /export/home/me/file: line6: E28: No such highlight group name: Comment '\[perl]\zs\_.\{-}\ze\[/perl]' Hit ENTER or type command to continue What am I missing? Contents of .vimrc: :set number :set hlsearch :set incsearch :set ignorecase :set shiftwidth=3 match Comment '\[perl]\zs\_.\{-}\ze\[/perl]' Thanks, K -Original Message- From: Gary Johnson [mailto:[EMAIL PROTECTED] Sent: Thursday, April 12, 2007 12:05 PM To: [EMAIL PROTECTED] Subject: Re: hilight blocks On 2007-04-12, Kirk [EMAIL PROTECTED] wrote: Is there any simple way to have custom blocks of code highlighted and the remaining code outside the blocks not highlighted? For example: # file.txt some plain text [my-custom-tag] some custom text [/my-custom-tag] Some more plain text ... # end of file So the idea would be to open VIM using file.txt and the code inside the custom tags would be highlighted. How about this? match Todo '\[my-custom-tag]\zs\_.\{-}\ze\[/my-custom-tag]' where you can certainly choose some highlight group other than Todo. You can put that line just as it is into your .vimrc, or put it in an after/ftplugin/txt.vim file, or create an autocommand to invoke it on just the files you want. HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Mobile Broadband Division | Spokane, Washington, USA
Re: hilight blocks
On 2007-04-12, Kirk [EMAIL PROTECTED] wrote: -Original Message- From: Gary Johnson [mailto:[EMAIL PROTECTED] Sent: Thursday, April 12, 2007 12:05 PM To: [EMAIL PROTECTED] Subject: Re: hilight blocks On 2007-04-12, Kirk [EMAIL PROTECTED] wrote: Is there any simple way to have custom blocks of code highlighted and the remaining code outside the blocks not highlighted? For example: # file.txt some plain text [my-custom-tag] some custom text [/my-custom-tag] Some more plain text ... # end of file So the idea would be to open VIM using file.txt and the code inside the custom tags would be highlighted. How about this? match Todo '\[my-custom-tag]\zs\_.\{-}\ze\[/my-custom-tag]' where you can certainly choose some highlight group other than Todo. You can put that line just as it is into your .vimrc, or put it in an after/ftplugin/txt.vim file, or create an autocommand to invoke it on just the files you want. HTH, Gary I like this one, I put it in my local ~/.vimrc file and it works for VIM (v6.1.3). But when I load this on another machine running VIM (v6.3) I get this error: bash-2.05$ vi file Error detected while processing /export/home/me/file: line6: E28: No such highlight group name: Comment '\[perl]\zs\_.\{-}\ze\[/perl]' Hit ENTER or type command to continue What am I missing? Contents of .vimrc: :set number :set hlsearch :set incsearch :set ignorecase :set shiftwidth=3 match Comment '\[perl]\zs\_.\{-}\ze\[/perl]' I don't know. :help hicolors and :help group-name in vim 7.0 both include the Comment group. The Comment group is used in so many examples in the vim help files and comments are such common aspects of programming languages that I would think that that group has existed since vim first had highlight groups. I see that if I start vim as 'vim -u NONE' and execute :verbose hi Comment I get the error message E411: highlight group not found: Comment but if I then execute :syn manual :verbose hi Comment I get the response Commentxxx term=bold ctermfg=4 guifg=Blue Last set from ~/src/Linux/vim-7.0/share/vim/vim70/syntax/syncolor.vim So from that I conclude that you have to execute a :syn command of some sort in some initialization file before before referring to any of the highlight groups in your .vimrc. I'll bet the machine running vim 6.1.3 has an initialization file that includes :syn on and the machine running vim 6.3 does not. This is probably discussed in the vim manual someplace, but I didn't go looking for it. HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Mobile Broadband Division | Spokane, Washington, USA