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
1
vote
1answer
29 views

Enable Expr Folding in Markdown

I want to fold in markdown using the built in markdown plugin that I believe should come with the version of vim I have (Vi IMproved 8.1 (2018 May 18, compiled Apr 23 2019 20:02:08)). I am struggling ...
3
votes
1answer
179 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 ...
0
votes
1answer
33 views

Folding RSpec content not depth

Trying to fold content so the 'method definition' / 'explanatory' lines are all showing regardless of depth, and the content between them is folded. Folding examples on the wikis and in tutorials all ...
5
votes
1answer
132 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 ...
5
votes
1answer
242 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: ...
2
votes
3answers
206 views

vim-orgmode: unfold everything on file open by default

Currently when I open files in org mode all the top level bullet points are folded. I can see why this is an OK default for a lot of people, but I prefer all text unfolded initially. Is there a ...
4
votes
1answer
55 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://...
15
votes
3answers
5k 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 ...
0
votes
0answers
24 views

folding code and moving along?

I recently discovered that vim can fold code. It works quite good with zc but when I move down with j then the code unfolds. How how can I prevent it from unfolding when I move with the cursor? Is ...
0
votes
1answer
33 views

Debugging foldexpr function

I have debug=msg,throw in my .vimrc. When trying to debug a foldexpr function, the echom statements I use to print are ignored and are not accessible by :messages. Any way to make them work?
1
vote
2answers
197 views

Fold special comments

I want to fold all special documentation comments, and only all special documentation comments. To do that I created a new syntax, doxygenComment and added highlighting (in red, just to test it). The ...
0
votes
1answer
21 views

Hide foldcolumn when no folds?

Currently I have set foldcolumn=1, but in a buffer with no folds, it's just a waste of space. Is there a convenient event to listen to in order to automatically toggle it between 0 and 1 (or whatever ...
0
votes
1answer
65 views

folding in matlab

I'm using vim for my matlab editor. And It works nicely, except I cannot get folding to work. I found my syntax file on github: matlab.vim And I wanted to add folding. I changed the line syn ...
0
votes
1answer
18 views

Pattern not found: lastlevel = -1

I'm getting one or more of these message when I open up a file I fold with a custom foldexpr function: Pattern not found: lastlevel = -1 I'm not sure what's generating except the lastlevel variable ...
0
votes
1answer
60 views

Fold: Different highlight style for fold of each filetype

Extend of this question of fold: Fold: foldtext() for each filetype We have fold for each filetype now but each fold need different highlight style of color, because highlight is global I tried to ...
0
votes
0answers
23 views

File is not folding when opened

Trying to figure out why folds aren't happening as soon as I open a file: set foldenable set foldmethod=expr let g:lastnum = 0 function! FoldFile(lnum) echom 'hi'; if getline(a:lnum) =~? '\v^\...
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 ...
21
votes
8answers
4k 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 ...
1
vote
0answers
42 views

custom fold expression to fold functions

I would like to create a custom fold expression for functions of the form x <- function(a,b,c) { ... ... body ... } where the lines starting from function(...) until the closing brace are ...
0
votes
1answer
50 views

Define a fold that can not be searched, and that isn't affected by other fold commands?

POD is a markup file that is used by Perl. It's a pretty unreasonable documentation format that has nothing to do with perl (accept for being the only known use-case), and it's sometimes found ...
0
votes
1answer
47 views

Is it possible to use newlines in a fold marker?

I am trying to set foldmarker={{{,\n\n\n, so that {{{ starts a fold and two consecutive empty lines end a fold. However, vim treats this as equivalent to foldmarker={{{,nnn. Is it possible to use ...
2
votes
1answer
65 views

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

How to unravel wrapped text

One of the files I have has "wrapped" text : Any idea how to unravel it? I am not sure if this is feature of any of my plugins. List of my plugins: Plugin 'VundleVim/Vundle.vim' Plugin 'tpope/vim-...
5
votes
1answer
715 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. ...
1
vote
1answer
874 views

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? ...
0
votes
2answers
60 views

Vim: Foldtext contain all content, instead of only the first line

Would like to have all content of the folded block, instead of only the first line. My current foldsettings are: set foldmethod=marker set foldmarker={,} Example how my data is structured: { ...
1
vote
0answers
64 views

Is there a way to customize the characters used in fold column?

Seems to me that fillchars option doesn't include these characters.
1
vote
2answers
181 views

How to select/delete/yank the contents of only the current fold?

When using foldmethod=marker, how do you select or reference exactly the contents of the current fold? I want to swap the order of two folds. If they were paragraphs, I would do dap { p. However, I ...
6
votes
1answer
810 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 ...
1
vote
2answers
102 views

Keep current line in same position when toggling folds (zi)?

When toggling folds with zi, any folds expanding above the current line cause the current line to disorientingly jump to a different place on the screen. How can I keep the current line fixed in the ...
0
votes
1answer
50 views

Vim: Is it possible to modify syntax rule of the Folded group?

Thank Vim's folding, I can hide irrelevant parts of code/document and work on a small spot of the file. More and more I organize the folded first lines as an outline of the whole file, in each level. ...
0
votes
1answer
101 views

Why does vim ignore commentstring when folding (foldmethod=marker)

I am editing a HTML document (filetype=html) in vim. foldmarker is set to {,}, foldmethod to marker and commentstring to <!--%s-->. When I visually select a region and use zf to create a ...
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 ...
2
votes
0answers
34 views

Setup to not automatically open/close folds when writing fold-markers (in the presence of a modeline)

Say I have a file: // vim: syntax=rust fdm=syntax { blah blah } Let's say that lines 2 through 4 are folded: // vim: syntax=rust fdm=syntax + { ... } Now I am in insert mode. I insert a newline ...
0
votes
1answer
96 views

Fold: highlight folded text only

I expected the folded text highlighted as below picture (ignore red rectangle): Like above picture, I'd like to have something to recognize that red region of a fold and highlight it only, donot have ...
1
vote
1answer
102 views

Fold: foldtext() for each filetype

how to have foldtext() for each filetype, because each filetype has different kind of fold so multiple foldtext() in vimrc and enable for each filetype. I'm thinking about multiple foldtext() ...
0
votes
2answers
42 views

Is the number of foldtext dashes incorrect?

Ref to :h foldtext() The number of leading dashes depends on the foldlevel. As follow, I think the foldlevel of printf is 1. But, you can see as follow, the number of dashes is 2. I can't ...
2
votes
1answer
49 views

How to visual select everything within a pair of fold markers

Are there simple tweaks that I can visual select everything with in a pair of fold markers? Just like what vi" will do for a pair of double quotes. Preferably vi plus some other keys.
6
votes
2answers
201 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="...
0
votes
2answers
131 views

Vim: Don't close fold when closing file

Is there a way to make vim not close the current fold I'm in when I close a file? For example: I am typing inside a fold, I save and close the file (without presing zc to close the fold), and then ...
1
vote
1answer
30 views

excluding line numbering from mkview/loadview

I include set number in my .vimrc file to have line numbers automatically displayed upon opening a file. I also use the following code block to automatically save and load the view when closing and ...
1
vote
2answers
63 views

separating folds with constant amount of newlines

Is there a succinct way to separate folds, open or closed, by the same number of newlines throughout the buffer? I'm using fold by indent. The goal is two visible blank lines between each fold (...
21
votes
1answer
6k 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:{ ...
2
votes
1answer
99 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) ...
6
votes
1answer
502 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 ...
3
votes
2answers
4k 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 ...
8
votes
2answers
2k 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 ...
1
vote
0answers
231 views

How to prevent Vim to collapse a fold with foldmethod=indent on a text paste?

I have the foldmethod=indent setting, the problem with it is that when I'm pasting a line or lines before the first line of a fold and all of these lines have the same or a greater level of ...
2
votes
1answer
558 views

Recursively open all folds in current open fold?

If I am in an open fold containing closed folds, how do I recursively open all those closed folds? I kind of thought this would be the use-case for zO, but it seems zO only works when the fold is ...
6
votes
2answers
213 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 ...