Hot answers tagged

95 votes
Accepted

How to fold text in a JSON file?

Yes, it is possible. A minimal setup would be: :set filetype=json :syntax on :set foldmethod=syntax
grodzik's user avatar
  • 4,528
42 votes
Accepted

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

As Jorengarenar said in their answer "{{{2 has to do with foldmarkers. Now, what are foldmarkers anyway? What are they useful for? And how do you use them? First let's notice that the strings you ...
statox's user avatar
  • 49.4k
13 votes

Is there a best practice to fold a vimrc file

It is a good idea to first define your own categories in your .vimrc (like a list with sublists and subsublists) and add all your plugins/settings/functions to the respective categories. Combined with ...
cbaumhardt's user avatar
  • 2,089
12 votes
Accepted

How to make jump to line automatically unfold

The foldopen setting controls which commands will open folds. In :help 'foldopen' we can see the list of possible values: item commands all any ...
Martin Tournoij's user avatar
11 votes
Accepted

oneliner map to fold all / unfold all

So you want to toggle between all lines folded and no lines folded. Does this mapping do what you want? :nnoremap <expr> <f2> &foldlevel ? 'zM' :'zR'
Christian Brabandt's user avatar
10 votes

Can I save folds?

I do exactly this for one file I refer to a lot NOTES.otl I performed the following in my .vimrc: " Useful for my Quick Notes feature in my tmuxrc augroup QuickNotes au BufWrite,VimLeave NOTES.otl ...
Sukima's user avatar
  • 1,192
10 votes

Hide certain lines completely (not folding)

I don't know how to achieve exactly what you want, only a part. You want to hide some text inside ~/.vimrc (for example). First we need to know which highlight group handles the text you want to ...
saginaw's user avatar
  • 6,706
10 votes
Accepted

Use of Foldcolumns in Vim

They indicate folds and their nesting levels: A + plus symbol marks a closed fold, and a - minus marks the first line of an open fold. If foldcolumn is high enough (i.e. greater that the number of ...
Rich's user avatar
  • 31.3k
10 votes
Accepted

Is there a way to edit only part of a file?

You could try the terrific NarrwRgn plugin by our very own Christian Brabandt, which has always worked very well for me. Just select the lines you're interested in in visual mode, and then type :NR ...
Rich's user avatar
  • 31.3k
9 votes
Accepted

Get rid of extra fold dashes when using Vim folding

You can set fillchars=fold:\ See :h fillchars.
Karl Yngve Lervåg's user avatar
9 votes
Accepted

Folding slow with vimtex

First: Did you bother to read the vimtex documentation, i.e. :h vimtex-folding? The docs clearly point out that the fold-expr method of folding is slow, and so therefore provides an option g:...
Karl Yngve Lervåg's user avatar
9 votes
Accepted

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

You can use the line() function to fold or unfold your file: " In your vimrc if line('$') > 20 set foldlevel = 1 endif line('$') returns the line number of the last ($) line of your document. ...
nobe4's user avatar
  • 15.9k
9 votes
Accepted

Brace { } navigation without opening folds

Thanks to @romainl for this answer on super user. I couldn't have written this without their help! You can use the foldopen option to determine which set of motions will or won't open a fold. From :h ...
DJMcMayhem's user avatar
  • 17.4k
8 votes
Accepted

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

You can hack around with some custom syntax and the use of the conceal: syntax region FunctionArguments start=+(+hs=e+1 end=+)+he=e-1 conceal cchar=… set concealleval=1 e.g. function (a, b, c, d, e)...
nobe4's user avatar
  • 15.9k
8 votes
Accepted

Recursively open all folds in current open fold?

I don't think there's anything shorter than zczA. That's pretty easy and probably what I'd do. I guess you could shorten it a bit with a mapping ;) :nnoremap <leader>O zczA But let's say you ...
B Layer's user avatar
  • 19.6k
7 votes

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

Markdown folding: As ana found out, for markdown specifically make sure that you have let g:markdown_folding = 1 or folding wont be "turned on". General folding tips: Vim won't fold automatically, ...
Tumbler41's user avatar
  • 7,706
6 votes
Accepted

Keep beginning of current fold on top of the screen

So following the idea I suggested in comments here is what I've come up with: First let's demonstrate it with a gif (I'm not sure why the cursor leaves this ugly mark): The idea is to: Set the ...
statox's user avatar
  • 49.4k
6 votes
Accepted

Count number of visible lines in document with folding?

Nice idea! Here's a basic function that achieves your goal using a different technique: function! FitOnPage() normal! zR while &foldlevel > 0 if line('w0') == 1 && line('w$') ==...
Rich's user avatar
  • 31.3k
6 votes
Accepted

Strange Fold Info Showing in Gutter

What you see is the 'foldcolumn' setting for opened folds. If you don't want it, simply disable it: :set foldcolumn=0 To find out where it was set, enter :verbose set foldcolumn? You might also play ...
Christian Brabandt's user avatar
6 votes
Accepted

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

There is no text object for folds in vim, but there is a plugin which provides them, az/iz: https://github.com/kana/vim-textobj-fold Here are vanilla alternatives: vi{/va{. This may or may not ...
Mass's user avatar
  • 14k
6 votes

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

To delete the current fold, you simply have zd for instance Otherwise, you could also define an operator-pending mode mapping with for instance: :onoremap iz :<c-u>normal! [zV]z<cr> ...
Luc Hermitte's user avatar
6 votes

Shuffle multiline folds

There is a :folddoclosed command which iterates over all closed folds (just like :g command for the whole buffer) and executes one or more commands on them. So I would close all folds, convert each ...
Jürgen Krämer's user avatar
5 votes

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

EDIT Actually I should have digged the doc a little more: using the syntax match is much more appropriate than the syntax region for what I want to do: The final solution that I will use it the ...
statox's user avatar
  • 49.4k
5 votes
Accepted

How to change the fold title in vim

No problem. Here is a basic implementation: set foldtext=FoldText() function! FoldText() let l:fs = match(getline(v:foldstart, v:foldend), '"label":') if l:fs < 0 return foldtext() ...
Mass's user avatar
  • 14k
5 votes
Accepted

Re-sync _folds_ from start

It sounds like you're looking for zx or zX. From the Vim documentation on fold, zx Update folds: Undo manually opened and closed folds: re-apply 'foldlevel', then do "zv": View cursor line. ...
Herb's user avatar
  • 1,203
5 votes
Accepted

How to unravel wrapped text

First of all the "wrapped" text is actually a folded text (see :h folds) To open the closed folds, you can Place your cursor on the folded texts and do zo to open it (see :h zo) Place your cursor on ...
3N4N's user avatar
  • 5,544
5 votes
Accepted

Only Open Folds With z Commands

You can set the 'foldopen' option to control which commands or movements will open folds. The specific cases you mentioned: h or l: these are horizontal movements, controlled by the hor setting. ...
filbranden's user avatar
  • 28.4k
5 votes
Accepted

How do you disable automatic code folding?

Put set nofoldenable in your vimrc. This will also accomplish what your autocommand does.
Mason's user avatar
  • 511
4 votes
Accepted

Folding my .vimrc doesn't work as expected

Make the else if an elseif. Also I find it usually simpler to give the variable v:lnum as parameter to the foldfunction. This makes it easier to debug the function. Some hints: You can use :set ...
Christian Brabandt's user avatar
4 votes
Accepted

Fold outside a selection

A very basic solution would be to use the following macro: qqggzf'<'>zfGq First visually select the text you want to focus on and use the macro with @q. To detail: qq start recording the ...
statox's user avatar
  • 49.4k

Only top scored, non community-wiki answers of a minimum length are eligible