8

I am in a project with 3 people. We need to have the same folds in Vim for each member. How can I share my folds?

[Feedback]

I understood one important thing: Google ignores signs, such as {{{, so please google "VIM three braces" to find help about the marker-method. It becomes much easier to practise, as you can quickly find relevant information.

In order to use the the marker-method (suggested by Adam Bellaire), please note that you have to set the method:

:set foldmethod=marker

Thanks for your answers!

tuk0z
  • 578
  • 4
  • 13
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

4 Answers4

18

Probably the easiest way is to just use fold markers (e.g. {{{1), making sure to include the vim:fdm=marker setting in the file itself. For example, here's a shell script which contains both the setting to use fold markers and two levels of fold:

#/bin/sh
# vim:fdm=marker
echo This file contains fold markers.

#Top Level Fold     {{{1
echo This is a top-level fold.

#Second Level Fold  {{{2
echo This is a second-level fold.

Opening this file in vim will show the first four lines and then a fold, which if expanded will reveal the second fold. Just make sure to put a space between your comment syntax and the vim:fdm=marker line or vim won't see it. For example, in C you could use:

// vim:fdm=marker
Adam Bellaire
  • 108,003
  • 19
  • 148
  • 163
  • 1
    Life changing. Well, you know not really, but amazingly useful all the same. Been using Vim on and off for about 6 years and can't believe I've only just found this out. – atomicules Jun 15 '11 at 14:20
5

Folds in files ? Well, same settings should result in same folds.

Vim can fold in several ways: manually, by indent, by expression, by syntax, and by markers (by default, I believe are curved brackets, 3 of them).

So if you have the same vim version, and they haven't changed their syntax and indent files, let them check out your vimrc for foldmethod and foldmarker options, and copy them to their vimrc files. That should do it.

Rook
  • 60,248
  • 49
  • 165
  • 242
  • You can add vim: markers to the files to adjust options on a per-file basis for all Vim's (unless such autoloading is disabled). – strager Feb 07 '09 at 23:04
  • stranger: Yes, you're right. He can add the {{{ and }}}, but just to make sure it works I would suggest adding a modeline in those files as well then: "vim: fdm=marker", so he has autonomous files then. (if he doesn't change the marker default, but he can add that as well) – Rook Feb 07 '09 at 23:09
2

I haven't shared VIM folds with someone before, but if you're working on the same machine perhaps you can use VIM sessions, which will save your current state (including folds). Run the following command in VIM:

 mks! /path/to/session_file

Then your friend can load up the session file:

vim -s /path/to/session_file
chuckg
  • 9,195
  • 7
  • 28
  • 26
0

Ancient history, I know, but this may have appeared since the version of vim present in '09, and since I don't have an adequate reputation to comment yet, here we go.

The good news is that saving a view for the file should save manual folds as well, even nested folds.

The bad news is that I found it didn't produce consistent results under vim 7.0 (RHEL 5.5). This may have been fixed in a subsequent update that, sad to say, we aren't allowed to install.

Joe Sewell
  • 306
  • 1
  • 11