sponsor Vim development Vim logo Vim Book Ad

vxfold.vim : Fold cycling similar to emacs org-mode (using TAB key)

 script karma  Rating 9/3, Downloaded by 1558  Comments, bugs, improvements  Vim wiki

created by
Marko Mahnič
script type
This script implements a fold-cycling functionality similar to
the one in emacs org-mode.

Subfolds are open/closed each time TAB or Shift-TAB is pressed.
TAB operates on the lines below a heading that is in the current line.
Shift-TAB operates on the whole buffer.

After each press a step in the following cycle will be performed:
   1. fold closed
   2. show direct subheadings
   3. show structure below heading + first line of text
   4. unfold all

   NOTES: It is possible to skip step 2 and/or 3, but the per-buffer
   configuration is still missing (I think emacs-org uses only 1-2-4). In step
   2 the text under the current heading may be visible; this is because of
   the way folding is implemented in Vim.

Fold cycling will work in buffers that are folded in the following way:
  * headings have folding levels 1-9
  * text has a folding level higher than 9

This means that the script can work with TVO (vimscript#517) without
changing the folding mode. To enable fold cycling in TVO mode:


For other modes the foldmethod has to be changed. Foldmethods are
provided for viki (vimscript#861) and vimwiki (vimscript#2226).


The later commands will also work on any buffer that has the headings defined
with a number of characters at the beginning of line (viki='*', vimwiki='=').

If a file uses '#' characters to mark headings with levels, it is also possible
to use fold cycling in it like this:

  :call vxfold#SetFold_OrgBolCount('#')

The display of the folded text can be changed with

  :call vxfold#SetFoldTextFirstLine()

which is the default for VxFoldVimWiki and VxFoldViki.

Please report bugs/suggestions on the Vim/Wiki (link top right).

install details
Unpack into vim runtime directory (eg. ~/.vim)

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vxfold.zip 0.2 2011-01-22 7.2 Marko Mahnič * fold expression settings changed to buffer-local
vxfold.zip 0.1 2010-03-02 7.2 Marko Mahnič Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.