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
152 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 ...
1
vote
3answers
218 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 ...
1
vote
1answer
92 views

cnoremap <CR> <CR> breaks search fold opening

In order to switch between relative and absolute line numbering upon entering command-line, I noremap <expr> <CR> to "someStuff". Unfortunately this breaks the foldopen-ing feature for ...
1
vote
2answers
264 views

Set folding method for c and cpp files, but not h and hpp

I am in the process of customizing my vim setup, and since I write a lot in C, I have a whole function dedicated just for those files, which I call with autocmd filetype c,cpp,h,hpp call C_syntax(). ...
1
vote
2answers
141 views

How do I keep folds when formatting (reindenting) the whole file?

I do quite often use this mapping: autocmd FileType cpp nnoremap <buffer> == :%!clang-format -style=file<cr>2g;zz It reindents the whole file and returns the cursor to the last edit ...
1
vote
2answers
860 views

Setting foldmethod=expr when re-sourcing vimrc?

I have the following on my vimrc file to handle custom folding: " ++ Folding set foldenable " enable folding ...
1
vote
1answer
17 views

Fold swagger verb properties

I have to edit regularly swagger JSON files to add a x-amazon-apigateway-integration property, files looks like: { "openapi": "3.0.0", "info": { "version&...
1
vote
1answer
20 views

sass folding syntax

i have foldmethod=indent on a .sass file. it auto-folds most blocks fine, except for #id selectors, which it folds into the block above it. for example: :root // folds 3 lines below --base-bg: #...
1
vote
1answer
21 views

What is corrupting my folds? And, more importantly, how can I fix it?

From time to time, I'll open up a document in vim and find that my manual folds are completely messed up. It's like vim decides to ignore its usual markers and, instead, start interpreting random bits ...
1
vote
1answer
55 views

Make fold feature act like Emacs's org-mode fold

In Emacs org-mode, folds use * at the start of the lines, and any * added consecutively, will add a level of indentation to the header. Furthermore, the header text placed after * or any number of it, ...
1
vote
1answer
184 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
2answers
109 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
1answer
139 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 ...
1
vote
1answer
259 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() ...
1
vote
1answer
86 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
208 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 (...
1
vote
1answer
42 views

Automatic folding based on bol

How might Ι automatically fold all paragraphs where every line begins with %%? Would be good for comments in TeX.
1
vote
1answer
452 views

Vim reseting to foldmethod=manual once navigating buffers

I have created a ftplugin/html.vim file with a custom fold expression. On my .vimrc file I have the following: set foldmethod=syntax "all files use syntax fold method autocmd Syntax html set ...
1
vote
1answer
40 views

Why does creating a new fold sometimes cause the entire file to be folded?

Sometimes when I create a new fold in vim, it folds the entire file. Why? (foldmethod=manual) e.g., zi (all folds are now open) zi (all folds are now closed) lines 1-309 are folded closed, and lines ...
1
vote
1answer
32 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 ...
1
vote
1answer
34 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 ...
1
vote
1answer
63 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
1answer
61 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
156 views

Vim template/skeleton with folding

I currently have a skeleton file so that whenever I create a new .cpp file, it copies the c++_template.cpp to the new file. I'm using this line in my .vimrc: autocmd BufNewFile *.cpp 0r ~/workspace_c+...
1
vote
2answers
1k views

Folding - open all, close one

There are a few commands to use folding (amongst all): za When on a closed fold: open it. [...] When on an open fold: close it [...] zA When on a closed fold: open it recursively. ...
1
vote
1answer
293 views

fold-expr not working as expected

I have trouble with one specific folding expression, s1. The documentation (:h fold-expr) says: "s1", "s2", .. subtract one, two, .. from the fold level of the previous line However ...
1
vote
1answer
56 views

Is it possible for a :map to insert text without fold-closing the inserted text AND leaving the other folds as they are?

I am facing the following problem: a function, triggered by a :nnoremap inserts a few lines into a buffer. Since I have folding enabled with foldexpr=... and the inserted text contains this expression,...
1
vote
0answers
31 views

Adding a syntax group to support fold markers with foldmethod=syntax

With foldmethod=syntax, is it possible to create a syntax group that matches my fold markers, so that i can use both language-specific syntax folding and whatever markers might already be in my code? ...
1
vote
1answer
25 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
0answers
25 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
27 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 ...
1
vote
0answers
50 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 ...
1
vote
0answers
108 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 ...
1
vote
0answers
64 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 ...
1
vote
0answers
115 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
1answer
150 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 ...
1
vote
0answers
321 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 ...
1
vote
2answers
122 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 ...
1
vote
2answers
302 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 ...
1
vote
0answers
46 views

How to show a list of SCSS rules in vim?

Is there any good outliner for SCSS files in Vim? Or alternatively, is it possible to fold SCSS classes such that the inner classes would be visible as well?
1
vote
1answer
74 views

Saving object state between foldlevel calls

I am trying to implement a custom folding function in a way that precomputes all the folds in a single pass and then reports the required foldlevels as needed. To do so, I use a single dictionary that ...
1
vote
0answers
1k views

autocmd not being executed when opening file

I've added the following lines to my .vimrc after reading about folding the other day (taken from vim.wikia.com): autocmd Syntax html,python,tex setlocal foldmethod=indent autocmd Syntax html,python,...
1
vote
0answers
34 views

How to save folds? [duplicate]

I made a few folds in my file, but they were gone after I closed it. I'd like to save them somehow somewhere, and teach vim to automatically load them when I open this file.
0
votes
1answer
132 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 ...
0
votes
2answers
83 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 ...
0
votes
2answers
911 views

No folding of markdown files

Running neovim 0.1.7. When I open a markdown file, it does not fold - even when I try zM zR zc, etc. :set tells me ft=markdown and foldmethod=syntax How do I get the folding?
0
votes
1answer
40 views

Is it possible to fold/unfold only one function

I'm trying to fold my c++ code. Google told me that I should set foldmethod=indent. But this is not what I need. set foldmethod=indent makes all of folds happen automatically when I enter a c++ file. ...
0
votes
1answer
192 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 ...
0
votes
1answer
122 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 ...