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.

Filter by
Sorted by
Tagged with
25
votes
1answer
7k views

How to fold text in a JSON file?

I have a large JSON file. It is not easy to work on all file at a time. I want to fold some content so that I can work on a section of JSON file. E.g.: { obj: {+}, // folded section obj:{ ...
21
votes
8answers
5k views

Is there a best practice to fold a vimrc file

I recently realized that my vimrc is now more than 400 lines long (which IMO is too much I'll try to reduce that) and to make it easier to navigate, read and edit it I decided to investigate the ...
16
votes
3answers
6k views

How to fold comments?

The syntax foldmethod is great, but sometimes I just want to fold the comments in a source file. Also syntax folding of comments only works for C-Style comments like: /* ... */ But not for ...
14
votes
1answer
6k views

Fold selected lines

How can I fold and unfold lines selected in visual mode? Lets say I have three paragraphs and I want to fold the first or last two into one line: Test ==== Lorem Ipsum es simplemente el texto de ...
13
votes
2answers
2k views

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 ...
13
votes
1answer
1k views

Folding by regex search pattern

I got a plain text file with whitespace separated columns of values. Like this: AU 3030 .... ... .... AU 3031 .... ... .... AU 3032 .... ... .... AU 3033 .... ... .... IT 48100 ... .. ..... IT ...
13
votes
1answer
3k views

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 ...
11
votes
2answers
3k views

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" ...
10
votes
3answers
4k views

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\" :...
10
votes
1answer
324 views

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.
9
votes
2answers
3k views

Folding fails: vim can't find any fold

I'm trying to fold some PHP code, and I have included a cut-down version of some of the code I'm trying to fold at the end of the post. I've tried the following vim commands, but only the ex commands ...
9
votes
2answers
317 views

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 ...
8
votes
1answer
3k views

HTML syntax folding in VIM?

I was wondering which is the best way to use syntax folding for HTML files. Specially if it can recognize javascript code within <script> tags. I typed set foldmethod=syntax but it does not ...
8
votes
2answers
3k views

Hide certain lines completely (not folding)

I would like to be able to hide certain lines in my buffer from showing up at all (and being able to toggle seeing them). I found similar questions, but they don't solve my problem. I don't want to ...
8
votes
2answers
631 views

Folding Python docstrings

According to the WIKI, scripts can be folded based on syntax. Does anyone have a solution to fold Python docstrings? Basically, all I need is to fold """ text between triple quotation marks """, like ...
8
votes
2answers
717 views

Is there a way to conceal across lines?

Here is my use case: I have lots of code which because of style enforcement we write newlines after and before each open and close brace (respectively). Example: function func(args) { ...
7
votes
1answer
588 views

How to map Enter to custom command EXCEPT in quick fix?

I've remapped <cr> (enter) to za so I can quickly open/close folds. However, now when I use the quickfix window and hit enter it no longer jumps to the line with the error (because it's trying ...
7
votes
1answer
572 views

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. ...
7
votes
1answer
257 views

Count number of visible lines in document with folding?

I'd like to write a plugin that automatically sets the foldlevel of a newly opened document so that as much of the document fits on the screen as possible. (In other words, I'd like to make sure short ...
7
votes
2answers
3k views

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 ...
7
votes
2answers
205 views

Is there a way to disable the foldexpr during autocomplete?

I've noticed that vim's fold method affects the efficiency of autocomplete, e.g. C-N is slow, and C-X L is hideously slow in medium sized files with relatively expensive foldexprs. I can't see the ...
7
votes
0answers
520 views

Highlight line number of folded lines

I want to have uniform highlighting of line numbers (provided by the LineNr and CursorLineNr hl-groups) but the line numbers of folded lines don't obey a particular group (as far as I know), but obey ...
6
votes
2answers
420 views

How can I enable folding only for files longer than a certain length?

By default, Vim will fold everything it can if folding is enabled. This can be useful from big complicated files, but it tends to get in the way for smaller, simpler files. For example, if I open a ...
6
votes
1answer
80 views

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 ...
6
votes
1answer
906 views

Get rid of extra fold dashes when using Vim folding

I am using the script from here, and it seems setting the g:custom_foldtext_max_width variable cannot get rid of the extra "--" symbols in the end of the folded lines. Is there any way to make the ...
6
votes
2answers
232 views

Fold/Unfold on moving vertically

Currently my init.vim (neovim's equivalent to the .vimrc) sets the foldmethod to marker: set foldmethod=marker When I open a file all sections are folded and if the curser is placed in the ...
6
votes
2answers
1k views

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 ...
6
votes
2answers
210 views

Syntax file: keywords within context

I have a language which uses statement like WHILE ... DO .. END_WHILE I can do the following in the corresponding synthax file syn keyword LangKeys WHILE DO END_WHILE syn region LangBlock start="...
5
votes
2answers
332 views

Is it possible to create a folding inside a single line?

The chapter 28 of User Manual says the following about folding: Folding is used to show a range of lines in the buffer as a single line on the screen. And all the examples of folding that I've ...
5
votes
2answers
482 views

How to create syntax folding for pascal

I mostly want it to automatically create folds for between a begin and an end, although if there's anything more advanced that would be welcome too. I've looked in the help for the pascal syntax and ...
5
votes
1answer
174 views

Keep beginning of current fold on top of the screen

I've googled around but can't find anything about this. There is a case: when I navigate deep down through large blocks of code in (for example) python, it would be useful to see which method, ...
5
votes
1answer
539 views

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: >&...
5
votes
1answer
588 views

Why I am losing syntax highlighting when folding code within a <script> tag?

I am working with an HTML file and within a <script> tag specifically. I usually fold my code using the marker method. However an annoying behavior sometimes happens with my syntax highlighting ...
5
votes
2answers
1k views

Change what vim displays when there is a fold

When I create a fold with zfap, vim displays something like: +-- 15 lines: myFunctionPrototype :: Test -> Test -> Bool However, I would like vim not to display this number of lines. I find ...
5
votes
1answer
763 views

Perl folding with perl_fold_blocks

I have the below settings in my .vimrc relating to Perl code folding. When I type za to toggle folding, it works on any sub { } by just folding up the sub. However, if I za a non-sub block (e.g. ...
5
votes
1answer
250 views

Highlighting after a line limit

I'd like to highlight sections of a document which are too long (measured in lines) so they will all print on a physical page. Sections are separated with ===. I tried to do it with this code: ...
5
votes
1answer
163 views

How to disable folding while typing?

I'm programming mostly in Python/Cython and use foldmethod=syntax (and foldclose=). Overall, this works fairly well, i.e. functions/classes/methods are folded reliably mostly. However, I have one ...
4
votes
3answers
285 views

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 ...
4
votes
1answer
431 views

Brace { } navigation without opening folds

I use {/} a lot for navigating around, but when I do this I never intend to open a fold and jump to blank lines within the fold. How can I nremap { and } to skip over folds?
4
votes
1answer
61 views

Shuffle multiline folds

Suppose I have a bunch of folds for more than one line each. How to make shuffle them as folds not lines? In case of lines it can be done by external shuf or any other command (see https://...
4
votes
2answers
932 views

Can I get vim to fold comments when using foldmethod=indent

When editing Python files at work I have to include 20+ lines of boilerplate legalese at the start of the file. "start of the file" is not that strict: I'm allowed to include the Python docstring, and ...
4
votes
1answer
3k views

Vimwiki: can't fold list items

With vimwiki you can fold headers and lists as following: Example for headers and list folding: = My current task = * [ ] Do stuff 1 * [ ] Do substuff 1.1 * [ ] Do substuff 1.2 * [ ] ...
4
votes
2answers
5k views

How to fold markdown using the built-in markdown mode?

Looking at the ftplugin file for markdown in Vim, it certainly appears that folding is supported, but I cannot get folding to work. If I have some content like this: # A heading Some content. More ...
3
votes
1answer
886 views

Can I use the mouse for folding/unfolding in Gvim?

The title says most of it. For the curious, folding is something I haven't yet included in my workflow. I use gvim most of the time and I often have my hand on the mouse, scrolling through code. Is ...
3
votes
1answer
127 views

Re-sync _folds_ from start

Vim has a handy feature in :syntax sync fromstart which allows me to fix syntax highlighting when it gets confused during an extended editing session. I map it to <leader>ss (reSync from Start) ...
3
votes
2answers
658 views

How to start Vimdiff without equal sections folded?

I'd like vimdiff to start with all the folded sections opened. So far I have tried the following: vimdiff -c "set nofoldenable" -R <(tree -d directory1) <(tree -d directory2) with the -c "set ...
3
votes
1answer
110 views

Writing a vim fold expression for fountain.io files

I am curious to see if it would be possible to write a vim fold expression for fountain.io files. Fountain files are plaintext files used by screenwriters. A good start would be to fold along two ...
3
votes
1answer
626 views

Modeline folding not working on help file

I'm writing a helpfile for a plugin, i.e. a foo.txt file that goes in the plugin's doc/ directory. At the bottom of that file I placed the following modeline: vim: tw=70 ft=help fdm=marker fmr={{{,}}...
3
votes
1answer
33 views

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 ...
3
votes
1answer
207 views

Expand all folds created by vim-latex when opening a LaTeX file

I want all my folds to be expanded when I open a LaTeX file. As per web search I added the following at the end of .vimrc set nofoldenable set foldlevelstart=99 set foldlevel=99 But even now its ...