Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically folding #defines in vim

Tags:

vim

scripting

I work with quite a bit of multi-platform C/C++ code, separated by common #defines (#if WIN, #if UNIX, etc). It would be nice if I could have vim automatically fold the sections I'm currently not interested in when I open a file. I've searched through the vim script archives, but I haven't found anything useful. Any suggestions? Places to start?

like image 994
Jon Tanner Avatar asked Sep 23 '08 14:09

Jon Tanner


People also ask

Is there a machine that will fold clothes?

Foldimate says that you can fold an entire load of laundry in about five minutes, which includes collared shirts, pants, and medium-sized towels.

Is FoldiMate real?

FoldiMate was a California-based company developing a robotic laundry-folding machine founded in 2012. Their clothes folding machine was aimed to enter the market by the end of 2019. In 2021, the company folded.


2 Answers

Just add a folding region to your syntax http://vim.wikia.com/wiki/Syntax_folding_of_Vim_scripts#Syntax_definitions

:syn region myFold start="\#IF" end="\#ENDIF" transparent fold
:syn sync fromstart
:set foldmethod=syntax
like image 78
hometoast Avatar answered Oct 06 '22 01:10

hometoast


To add to @hometoasts answer, you can add that command as a comment in the first ten or last ten lines of the file and vim will automatically use it for that file.

    /* vim: syn region regionName start="regex" end="regex": */
like image 44
DGentry Avatar answered Oct 06 '22 00:10

DGentry