tags:

views:

69

answers:

2

How can I export vim folds from a file, so that I can transfer it to a different machine?

For example say I create the folds in a file and save it on a local machine - where does the "folding" metadata go? Can I just copy it to another machine, or must I manually recreate the folds again?

EDIT: Hm, I've noticed this might be a duplicate question, but still there is not answer as to how to save the fold information WITHOUT modifying the source file.

Thanks

+1  A: 

Ok I've figured out a relatively painless way of doing it. This does require some change to the source file however.

First, set the fold-marker to be java style /** comment **/ markers:

:set foldmethod=marker
:set foldmarker=/\*\*,\*\*/

then inside my source any time I want a fold I just type:

/** This is the title of the section */
Some stuff goes here blah
...
//the line below "ends" the fold by double star
/* **/

This produces folds just as I expect them and is much easier to deal with than the "dynamic" or visual folding.

drozzy
+1  A: 

Save your session with the :mksession command, and restore it with vim -S Session.vim. The session file will restore almost everything, including folds (though changes to the file will mess it up).

That works if you must use manual folds, but it's really a lot easier to use one of the automatic fold methods — investigate indent, syntax, and expr, and look for syntax files that fully support folding.

jleedev
So you mean it stores a Session.vim file somewhere? Where?
drozzy
Current directory, or anywhere you want. All there in the manual.
jleedev
Since I usually launch gvim from a desktop icon, an alternative way to load the session file is to `:source Session.vim` once in the editor. (My usage is usually `:mks ~/properties.vim` at night and `:so ~/properties.vim` if I'm working on the properties system; a convenient name to remember what I was doing...)
dash-tom-bang