Lenin Lee wrote:
> I want to write notes and save them into plain text files, in my notes,
> there are always some pieces of code.
> 
> I want to apply syntax color of that language only to the block of code, is
> there a way to do so ?

I think the following tip from the Vim tips wiki describes how to do 
what you want.
http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file

If you want to highlight the plain text (non-code) within your file with 
arbitrary formats and colors (i.e., like rtf highlighting), you could 
use the Txtfmt plugin.
http://www.vim.org/scripts/script.php?script_id=2208

Here's a quick example of how I included C++ and Txtfmt regions within 
the same file.

--- inside snip.vim ---
:syntax on
:syntax include @CPP syntax/cpp.vim
:syntax region cppSnip matchgroup=Snip start="@begin=cpp@" 
end="@end=cpp@" contai...@cpp
:hi link Snip SpecialComment

:syntax include @TXTFMT syntax/txtfmt.vim
:syntax include ftplugin/txtfmt.vim
:syntax region txtfmtSnip matchgroup=Snip start="@begin=txtfmt@" 
end="@end=txtfmt@" contai...@txtfmt
:hi link Snip SpecialComment

--- inside snip.txt ---
@begin=cpp@
... C++ code here...
@end=cpp@

@begin=txtfmt@
...Plain text highlighted with Txtfmt here...
@end=txtfmt@

Note that you have to source snip.vim from within snip.txt. You can do 
so manually...
:so snip.vim
...but a better approach might be to use an autocommand: e.g., something 
like...
au! BufRead,BufNewFile *.snip           runtime syntax/snip.vim

Brett Stahlman

> 
> Thanks !
> 
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to