1

We are using a proprietary tool which uses Tcl and the C preprocessor to create input files. Is there any way to get the Tcl syntax highlighting to also recognize the #if, #else, #endif macro conditional from the C preprocessor. The goal would be to be able to quickly jump between the macro blocks with the % key.

This kind of works if we set the language to c:

:setf c

and then placing the mouse of the relevant macro conditional and hitting the % key

#if sldkfjlkj 
set dog cat
set dog cat
set dog cat
#else
#if 0
set dog cat
#else
set dog cat
#endif
#endif
  • 3
    you could try setting the filetype to "c.tcl" so that both filetype plugins are loaded. That only works however, if the syntax/filetype plugins support it. Or for your case, simply create a file ~/.vim/after/ftplugin/tcl.vim and set the b:match_words variables like from the ftplugin/c.vim file – Christian Brabandt Nov 9 '16 at 18:17
1

Motions between the macro blocks should already be covered by the built-in % motion; it expressly handles #if, #ifdef, #else, #elif, #endif; cp. :help %.

I've extracted the preprocessor-related syntax elements from the built-in C syntax file, and put them into a separate syntax extension script, now published as the syn-preproc plugin.

With that, it should be sufficient to

:setf tcl.preproc

and you enjoy highlighting and folding of #ifdef and so on in addition to the normal Tcl highlighting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.