Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Vim command to delete all fold markers in a file?

Tags:

vim

To delete a particular fold one can do zd.

To delete all fold markers one can execute:

:%s/# {{{//
:%s/# }}}//

But is there a command (like zd) to delete all markers?

like image 522
Xavier Nayrac Avatar asked Nov 30 '13 19:11

Xavier Nayrac


People also ask

How does folding work in Vim?

Vim uses the same movement commands to define folds. Folding also works in visual mode. If you enter visual mode using v or V , then select a few lines of text using the movement keys, and type zf , Vim will create a fold comprising those lines. Another option is to specify a range in command mode.

What is code folding in vim?

Code or text folding, or less commonly holophrasting, is a feature of some graphical user interfaces that allows the user to selectively hide ("fold") or display ("unfold") parts of a document. This allows the user to manage large amounts of text while viewing only those subsections that are currently of interest.


2 Answers

tl;dr zE is the command you are looking for.

Now for the long version.

Assuming:

  1. Your foldmethod is set to marker.
  2. Your foldmarker setting matches the fold markers in the file (in your case it's the default {{{,}}}).
  3. Your commentstring is set properly (this is almost certainly the case, unless vIM doesn't have a syntax file for the file type).

You can just use zE which Eliminates all folds in the file.

You can check the settings by running :set foldmethod? foldmarker? commentstring? and set them by running :set foldmethod=manual foldmarker={{{,}}} commentstring=#%s.

See the docs here: http://vimdoc.sourceforge.net/htmldoc/fold.html#zE

There are some caveats in the docs here: http://vimdoc.sourceforge.net/htmldoc/fold.html#fold-delete-marker

This does not work properly when:

  • A line contains more than one marker and one of them specifies a level. Only the first one is removed, without checking if this will have the desired effect of deleting the fold.

  • The marker contains a level number and is used to start or end several folds at the same time.

like image 55
Omni5cience Avatar answered Oct 28 '22 08:10

Omni5cience


I answer this myself:

To delete all fold markers, visually select all the file with ggVG before doing a zd.

like image 21
Xavier Nayrac Avatar answered Oct 28 '22 08:10

Xavier Nayrac