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
15
votes
2answers
4k views

What does three commented curly brackets ("{{{) at the end of a line mean? Is it just a comment?

In the tcomment plugin, specifically in: ~/.vim/pack/tml/start/tcomment.vim/autoload/tcomment.vim and ~/.vim/pack/tml/start/tcomment.vim/plugin/tcomment.vim I'm seeing this at the end of some lines: ...
2
votes
1answer
29 views

How can I fold some lines on opening a buffer?

I want to fold from "Copyright" to "CONNECTION" every time I open a .c or .h file, so I don't have to see it. The license does have newlines in it in my files, so selecting shouldn'...
2
votes
1answer
111 views

TeX/LaTeX vim fold markers options

In complex files, especially when writing packages with basic TeX-LaTeX code, the standard definition of foldmarker, namely {{{,}}}, is unfortunate — in effect is quite common to have pieces of code ...
1
vote
1answer
24 views

Better folding on file open — based on file length?

I like having files be opened folded, specially when they are large. However, when they are small, it can be an overkill (like a markdown file with a single heading). In such cases, I'd like to open ...
1
vote
0answers
26 views

Only close first fold when file is opened

When I open a file, I want to automatically fold all outer most folds, so no nesting. Here is what I currently have in my config: set fdm=syntax set foldnestmax=20 set foldenable " set foldlevel=99 ...
1
vote
1answer
24 views

maintain alignment of text after folding

When a block of text is folded in vim, the first line of folded text is displayed in the foldline at a constant offset from the left edge of the window. Can the offset of that text be instead set to ...
0
votes
0answers
34 views

vimscript: Efficient way to extract portion from line of text

I have a plugin that does syntax highlighting and folding for a kind of data file. The syntax and folding are both dependent on textual values in specific places (columns) of current line of text. ...
2
votes
1answer
19 views

Adding a new line after a fold

At the end of a file I have these lines, line 19 is actually a beginning of a 4 line fold. Now if I want to add a new line after the fold, i.e a new line number 24, I usually type 'A' and enter ...
1
vote
1answer
32 views

Is there any way to prevent modelines getting reapplied when files are saved / written?

For some Markdown documents, I like them to open with some sections initially folded (I use the plugin vim-markdown-folding). I've tried setting a modeline that looks like this: <!-- vi: set ...
0
votes
0answers
20 views

Unable to change foldmethod

I have the following simple line: inoremap <silent> <TAB> <C-o>:set foldmethod=manual<cr> However, after this command is run and I run set foldmethod?, it reports the ...
1
vote
0answers
18 views

XML syntax folding and custom tag spell checking

I have the following in my ~/vim/syntax/xrc.vim to spell check contents of specific tags when editing XRC files that are just XML files with predefined schema: runtime syntax/xml.vim " check ...
1
vote
0answers
22 views

vim - copy folds to a copied file

Any way to copy folds to a copied file? Example: file1 has several folds, now I create a new file cp file2 newfile. newfile doesn't have folds that I had created in vim, of course it won't as cp and ...
0
votes
0answers
15 views

How to limit nest-level for folds with vim-anyfold plugin

For folding java code (also nice for c, cpp, python etc.), I just installed the vim-anyfold plugin. In my ~/.vimrc, I've added autocmd Filetype java,c,cpp AnyFoldActivate to automatically activate ...
1
vote
1answer
62 views

Changing foldmarker per filetype with vim 8.2

On an up-to-date Arch system, I set up marker-based folds in vim and python scripts like so: Extracted from my ~/.vimrc [1] set nocompatible " default filetype plugin indent on set nofoldenable set ...
1
vote
0answers
30 views

Highlight color columns on top of folds (not below)

I'm highlighting folds and color columns in colors different from the background and from each other. Here's an excerpt of my vimrc with all (potentially) relevant lines: " ~/.vimrc ... " Folding ...
0
votes
0answers
32 views

“Invalid expression” setting 'foldtext', what is wrong?

I am trying to set 'foldtext', but it seems I misunderstand expressions, types, etc. of Vim fundamentally. Why does the following refuse to work? set foldtext=v:folddashes."TEST" Whereas this works?...
3
votes
1answer
62 views

How to search only in a text which is not folded?

I would like to use search in file with folded functions to search only in functions titles. But common vim search searches inside folding and unfolds any hidden text. Is there a way to search only in ...
1
vote
1answer
61 views

Automatically fold particular content, in any filetype

I often find myself patching projects that add a relatively big (23 lines out of a 37-line file? ) license-header to every. single. file. Is there a plugin or straightforward way I can add a global ...
1
vote
0answers
65 views

Folding in VimWiki like in org mode?

I moved from org mode to VimWiki. I used to write "logs" like this * 2020-02-04 FeatureA - progress Feature B - progress The file can get pretty long as you can imagine. Now with ...
0
votes
1answer
143 views

How do you disable automatic code folding?

I use foldmethod=indentbut I hate how it starts each file pre-folded. To get around this I put au BufWinEnter * normal zi in my vimrc. That had worked fine so far, but now that I started using CoC, My ...
1
vote
1answer
40 views

Deleting folds over a range

Working in an index with mucked up manual folds. Would like to delete folds from current line to end of file. Have tried: :.,$zd and :.,$df So far I've just done a visual selection from current ...
1
vote
3answers
134 views

Prevent VIM from folding a large file

For editing XML files I have the following in my init.vim " Automatically enable folding of XML-files augroup XML autocmd! autocmd FileType xml let g:xml_syntax_folding=1 autocmd FileType xml ...
0
votes
1answer
98 views

change fold sign character

I know per my question remove trailing dashes in foldtext that I can remove the trailing dashes from collapsed fold lines. When a fold is 'open', the sign column has pipe characters '|'. I looked at ...
1
vote
1answer
171 views

How to fold nested “if then else end if” statements

I try to write a vim syntax file for folding if-else statements with the syntax: if <condition> then <block to fold> [else <block to fold>] end if Current approach syn region Then ...
3
votes
1answer
56 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 ...
1
vote
1answer
39 views

How can I reset all folds to the state when the editor started?

I have some configuration in my .vimrc governing the initial folding strategy. Sometimes, I am looking to restore the initial state and would like a :refold command or something, which restores the ...
1
vote
1answer
66 views

How to prevent markdown folding of # comments in fenced code?

I have python examples in a markdown file in a code fence (e.g. when I convert a jupyter notebook into a markdown document). These snippets sometimes have code comments in them starting with #. The ...
1
vote
0answers
46 views

How to make code-folding more efficient

I have a ruby file while is about 5K+ lines long. My current setup uses the vim-ruby plugin. With this, I enable code folding with let ruby_fold = 1 This opens my ruby files pre-folded. I can open ...
2
votes
1answer
81 views

Only Open Folds With z Commands

If I navigate the first line of a folded function with h,l, etc it will open the fold. Navigating search matches with n will also open a fold if there is a match inside the fold. Can you configure ...
0
votes
1answer
118 views

Use line's 'folded state' in a mapping, so it's `zc` closing but `zv` opening?

When I'm opening a fold, I would say 100% of the time the behaviour I want is zv - open all folds covering the current line, so that I can actually see it. But zv won't close a fold. How can I use ...
1
vote
1answer
114 views

Editing file in splits breaks the folding

My current workflow looks something like this: Open a file in different splits, each split showing a different section Make appropriate edits in each split :wq from the split after editing Repeat as ...
3
votes
1answer
89 views

Record all line-number fold-levels and restore fold-states (despite fold-level change)

I have found myself so extraordinarily frustrated with Vim's foldmethod=syntax behavior that I've contemplated dropping the editor entirely, despite being mostly happy with it for a few years now. ...
1
vote
1answer
189 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 ...
4
votes
1answer
81 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://...
0
votes
1answer
93 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
55 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?
0
votes
1answer
20 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
0answers
51 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^\...
2
votes
0answers
87 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
132 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 ...
0
votes
1answer
56 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 ...
2
votes
1answer
71 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
58 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-...
0
votes
2answers
115 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
99 views

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

Seems to me that fillchars option doesn't include these characters.
0
votes
1answer
107 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
133 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 ...
2
votes
0answers
67 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
250 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 ...
0
votes
1answer
114 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 ...