sponsor Vim development Vim logo Vim Book Ad

syn-preproc : C preprocessor syntax on top of other syntaxes.

 script karma  Rating 1/1, Downloaded by 815  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
This syntax extension highlights C preprocessor directives and (optionally)
folds preprocessor conditions. You can use this as a standalone syntax, or add
this on top of another filetype.

If you have certain files of a particular filetype (e.g. Tcl) that contain
preprocessing directives, you can add a custom filetype detection (here: for a
"Tcl template" .tclt file extension; cp. new-filetype), and set a compound
    autocmd BufNewFile,BufRead *.tclt setf tcl.preproc

To add the highlighting to the file's existing syntax, use:
    :setf <C-R>=&filetype<CR>.preproc

To just have preprocessing highlighting (and no other syntax), use:
    :setlocal syntax=preproc

Note: This script supports both the normal "#..." syntax as well as the
alternative "%:..." digraph (or alternative token) for the '#' punctuator.
install details
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim syn-preproc*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.

For a permanent configuration, put the following commands into your vimrc:

C/C++-style comments are typically removed by the preprocessor and thus
highlighted as other comments. You can define a different highlighting if you
want to visually distinguish them from the default comments of that filetype:
    hi link preprocComment NonText
Or turn highlighting of comments off:
    let preproc_no_comments = 1
Multi-line C-style comments are folded; if you do not want this, use:
    let preproc_no_comment_fold = 1

To turn off folding of #if ... #endif conditions, use:
    :let preproc_no_fold_conditions = 1
Lines commented out via #if 0 will still be folded. To turn that of, too,
    :let preproc_no_if0_fold = 1
To completely turn off highlighting (as comments) of #if 0 blocks, use:
    :let preproc_no_if0 = 1

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
syn-preproc-1.00.vmb.gz 1.00 2016-11-17 7.0 Ingo Karkat Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.