tags:

views:

182

answers:

3

I have been searching a solution which puts the fold marks and codes to an external hidden file. This way you could have permanent folds without extra fold signs.

How can you control folds by an external file in Vim?

+4  A: 

That's a very general question. What is "an external file" in vim, really ? Vim is, after all, a collection of "external" files. So if I define my folding preferences in my vimfiles, is that "an external file" solution ?

You could link, for example, define regex mechanisms of folding and source them from an external file.

But I think, what you ment is, "can I define an external file, so I can have by project custom folding, so that everyone who uses vim after I give them my files, will have the same folding" ? Yes, I guess you could do that by extrapolating from the method above.

But remember, vim has several methods of folding:

  • manual - where you manually define folds (this is nice, but it leaves your code with lots of curly brackets, but it is "portable")
  • indenting - where indending defines folds
  • expression (which I mentioned)
  • syntax - defined by syntax highlighting
  • marker - you already know that

... in the end, it will all come down to those few settings in your vimrc.

My advice: DO NOT CHANGE vim's indenting, syntax, etc. files. Normally, you will not even need to change those (unless you're using a language vim has no support for, which I doubt). So, define your settings and preferences in your vimrc and vimfiles directory, and just give your coleagues preferences which they need (usually just those from vimrc) to have the same folding behaviour.

ldigas
Thank you very much! I have been seaching the syntax folding command for a long time.
Masi
+2  A: 

Use manual method of making folds. This is not the same as marker as implied above. Use :mkview to save folds and :loadview to reload them.

Karl
A: 

Vim can be made to atuomatically remember folds in a file by putting these two lines in ~/.vimrc

au BufWinLeave ?* mkview au BufWinEnter ?* silent loadview

Izkata