About: Folding for plain text files based on indentation   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

Folding based on indentation is the easiest and most intuitive way to hide sections of a file with minimal special formatting. However, I wanted a section of lines with the same indent to fold into a heading with less indent. This is not what the default behavior is, which folds into the first line with the same indent: Unfolded text: heading A line 1 line 2 line 3 heading B Default behavior (folded based on indent): heading A line 1 heading B What I wanted when folded: heading A heading B So, I put this in my vimrc to implement folding:

AttributesValues
rdfs:label
  • Folding for plain text files based on indentation
rdfs:comment
  • Folding based on indentation is the easiest and most intuitive way to hide sections of a file with minimal special formatting. However, I wanted a section of lines with the same indent to fold into a heading with less indent. This is not what the default behavior is, which folds into the first line with the same indent: Unfolded text: heading A line 1 line 2 line 3 heading B Default behavior (folded based on indent): heading A line 1 heading B What I wanted when folded: heading A heading B So, I put this in my vimrc to implement folding:
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1167(xsd:integer)
Category
  • Folding
Author
  • Paul Donohue
Complexity
  • advanced
Created
  • 2006-03-13(xsd:date)
ID
  • 1168(xsd:integer)
NEXT
  • 1171(xsd:integer)
Rating
  • 8(xsd:integer)
abstract
  • Folding based on indentation is the easiest and most intuitive way to hide sections of a file with minimal special formatting. However, I wanted a section of lines with the same indent to fold into a heading with less indent. This is not what the default behavior is, which folds into the first line with the same indent: Unfolded text: heading A line 1 line 2 line 3 heading B Default behavior (folded based on indent): heading A line 1 heading B What I wanted when folded: heading A heading B So, I put this in my vimrc to implement folding: setlocal foldmethod=expr setlocal foldexpr=(getline(v:lnum)=~'^$')?-1:((indent(v:lnum)'.indent(v:lnum+1)):indent(v:lnum)) set foldtext=getline(v:foldstart) set fillchars=fold:\ "(there's a space after that \) highlight Folded ctermfg=DarkGreen ctermbg=Black This will create folds based on a single-space indent (I wanted to be able to build a hierarchy many many levels deep, and using a tab for the fold indents very quickly pushed my text off the window, but I didn't want to mess with the tabstop). Blank lines are folded based on the surrounding indentation (they are not counted as a 0 indent line). I quickly got annoyed by the default key mappings for folding/unfolding sections, so I remapped Shift-Left/Shift-Right to close/open: nnoremap zo inoremap zo nnoremap zc inoremap zc " Shift-Up Shift-Down (incase Shift is held while browsing folds) nmap imap nmap imap But, I found that the default mappings for Alt-(Arrows) and Ctrl-(Arrows) sometimes caused Vim to do strange stuff, and I would occasionally hit those by accident, so I remapped those as well: " modified arrow keys do bad things by default " Ctrl-(Up, Down, Left, Right) noremap noremap! noremap noremap! noremap noremap! noremap noremap! " Alt-(Up, Down, Left, Right) noremap noremap! noremap noremap! noremap noremap! noremap noremap!
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software