Questions tagged [folding]

A feature which lets visually hide (and toggle) regions of a text file, by replacing its contents with a single outline line.

It is very useful to expand and collapse sections of a text file using folding, as it makes it easier to navigate around the document and to work on whole regions as they were single lines.

Folding is activated via the foldmethod (abbreviated to fdm) option, which is local to each of the and determines what kind of folding applies in the current window.

Possible values for foldmethod are:

  • manual – folds must be defined by entering commands (such as zf)
  • indent – groups of lines with the same indent form a fold
  • syntax – folds are defined by
  • expr – folds are defined by a user-defined expression

In addition, foldmethod may have values:

  • marker – special characters can be manually or automatically added to your text to flag the start and end of folds
  • diff – used to fold unchanged text when viewing differences (automatically set in mode)

For more information: Folding on vim.wikia

240 questions
18
votes
3 answers

Can I save folds?

Today I learned how to fold/unfold in Vim; it's quite handy. Unexpectedly, when I exit a file and reenter it, the folds I created are gone (unfolded). In our company's large project there are quite a lot of sticky (legacy) code blocks which are…
Zen
  • 333
  • 2
  • 7
16
votes
2 answers

Collapse vim folds to a single line, similar to Atom or Sublime Text

I'm a fan of the way that Atom and Sublime Text handle line folding, where the first line of each fold is visible (complete with syntax highlighting), and a marker is appended to the end of the line that indicates the fold. See the screenshot below…
Mike Hearn
  • 275
  • 2
  • 4
14
votes
3 answers

How do you fold functions automatically?

Is there a way to make Vim fold functions based on the syntax of a function declaration? For example having vim turn a function like this: def foobar(foo,bar): if foo > bar: print "foo" elif foo < bar: print "bar" elif foo == bar: …
Dom
  • 3,314
  • 5
  • 21
  • 38
13
votes
2 answers

How to open a file with all folds opened?

I've got the following line in my _vimrc file which enables folding for my PHP (and other) files: set foldmethod=indent However, whenever I open a file it starts with every fold closed, but I would like the file to start with its folds open. How…
John Sonderson
  • 617
  • 1
  • 6
  • 14
12
votes
3 answers

How to write a fold-expr?

I have read the help page about fold-expr (:h fold-expr) but it didn't explain what's the syntax used in the expression. There were there four examples: :set foldexpr=getline(v:lnum)[0]==\"\\t\" :set foldexpr=MyFoldLevel(v:lnum) :set…
elyashiv
  • 2,429
  • 2
  • 18
  • 23
10
votes
1 answer

Is there a way to display folded parts as a tree?

Folding is useful to hide away parts of the document. A visual representation of the folding structure as a tree would be useful for understanding the document structure at a glance.
Demetris
  • 465
  • 1
  • 5
  • 8
10
votes
1 answer

How to make jump to line automatically unfold

When I jump to line (:76) I end up on a fold, but it doesn't open. I can quickly unfold the fold and it gets to the right line, but I want to have the fold unfold automatically to save keystrokes. Is there a way this can be achieved?
hakunin
  • 269
  • 1
  • 7
9
votes
2 answers

Problem: Moving lines vertically closes folds

When I move lines with m (e.g. :m+1) all my folds are closed. I can then open the folding with zv again and the cursor will be at the position I moved to. I use folding with {{{ }}} marks and have set foldmethod=marker in my .vimrc. How can I…
dnieder
  • 91
  • 2
7
votes
2 answers

How to save a view (with folds) into the file?

I just recently learned how to use folds and I find it very useful. I have added a rule to automatically save the view with my folds when I'm editing the markdown files with the rule: augroup QuickNotes au BufWinLeave *.md mkview au BufWinEnter…
lewiatan
  • 421
  • 6
  • 15
6
votes
1 answer

save unfolded data to separate file

Within vim you can fold away some data that doesn't pertain to what you're looking for at that moment. So I'd like to save that unfolded data to a separate file and look at it closer, but I don't know the correct/exact combinations to do this. I…
6
votes
1 answer

Use of Foldcolumns in Vim

I never thought of the use of foldcolumns in vim. There are - and + signs to indicate foldable or folded parts of the code, that I understand. But what about the numbers inside the cosecutive - signs? If I increase foldcolumn width the numbers take…
3N4N
  • 5,684
  • 18
  • 45
5
votes
3 answers

Fold outside a selection

Sometimes, when I edit a large file, I like to focus only on a part of the document and not all of it. Is it possible to create a sort of fold that wrap a part of the document (e.g. the current function/paragraph) so the focus is narrowed on that…
nobe4
  • 16,033
  • 4
  • 48
  • 81
5
votes
1 answer

Fold with markers, but disable nesting?

I want to fold sections in a document. Each new section should define a top-level fold instead of a nested fold. I want to use a single delimiter to define a fold. Consider an example document: >>> first fold also in first fold >>> second fold still…
John Freeman
  • 227
  • 1
  • 6
5
votes
1 answer

remove trailing dashes in foldtext

When I set foldtext to a simple value like getline(v:foldstart), vim should show the current line, as opposed to the usual + and appropriate number of hyphens - for the foldlevel. However, vim fills the remaining space till the far side of the…
myc3lium
  • 53
  • 2
4
votes
1 answer

Is there a way to edit only part of a file?

Unlike many people who are looking for this, or a similar sort of feature, it's not actually the file size I care about, I just find myself needing to deal with a very specific section of a file - maybe a couple hundred lines or less, so typically…
Wayne Werner
  • 425
  • 2
  • 7
1
2 3 4 5