Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use vim to edit Informix 4GL source code which has this sort of syntax:

  FOR ...

I wish to fold the functions using za zM etc

This works

  :set foldmarker=FUNCTION,END\ FUNCTION
  :set foldmethod=marker

However the keywords can also be in lower case and I'd ideally also like to fold MAIN..END MAIN, so markers are not able to do this.

I tried

:syn region myFun start="FUNCTION" end="END FUNCTION" transparent fold
:set foldmethod=syntax

but it had no effect. I already have a syntax file that does color highlighting and :syn showed myFun included in the syntax definitions.

How can I configure case-independent syntax folding of FUNCTION...END FUNCTION and MAIN..END MAIN ?

Update: I have tried but it has some problems:

  • It folds at a level of detail I don't want (IF, FOR, WHILE, ...)
  • It assumes END statements start on a new line (so IF a<b call c() END IF folds to EOF)
  • It thinks SELECT * FROM table \n FOR UPDATE is the start of a FOR statement

So I'd like to try creating something much simpler first.

share|improve this question
What language is this? – digitxp Aug 17 '11 at 17:17
Informix 4GL. I have found a syntax file for it but it folds more than I want (IF statements), has bugs (e.g. when "END IF" on same line as "IF", or counts "SELECT * FROM table FOR UPDATE" as start of FOR loop) and doesn't fold FUNCTION! (though the file seems to have code for folding functions) – RedGrittyBrick Aug 17 '11 at 17:21
Did you try set foldmethod=indent? – romainl Aug 17 '11 at 20:25
@romainl: I hadn't but I have now. It's not ideal for me but it is useful. Thanks. – RedGrittyBrick Aug 17 '11 at 23:08
up vote 1 down vote accepted

I think you should define your own folding function, that way you will have more control over what is folded when. The following fold function folds function/end function case insensitively, and should be fairly easy to adjust for further requirements:

function! InformixFold()
  let line      = getline(v:lnum)
  let prev_line = getline(v:lnum-1)

  if match(line, '^\s*function\s*$') >= 0
    return 1
  elseif match(prev_line, '^\s*end\s*function\s*$') >= 0
    return 0
    return "="

Then set foldmethod to expr and foldexpr to the function:

set foldmethod=expr
set foldexpr=InformixFold()

See help fold-expr for more.


|   FOR ...
|   ...

+ +--  5 lines: FUNCTION------------------------------------------------------
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .