Skip to main content
98 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,658
42 votes
Accepted

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

"{{{2 is a foldmarker. Now, what are foldmarkers anyway? What are they useful for? And how do you use them? First let's notice that the strings you mention in your question are composed of three ...
statox's user avatar
  • 50.1k
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
11 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
  • 32.2k
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
  • 32.2k
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
  • 16.1k
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.7k
8 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,756
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
  • 20k
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
  • 50.1k
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
  • 32.2k
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
  • 14.2k
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
  • 17.5k
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
6 votes
Accepted

Disable Vim folding for short files

I would do: autocmd! BufRead * if line('$') < 100 | setlocal nofoldenable | else | setlocal foldenable | endif Explanation: The autocmd BufRead * trigers the corresponding code when the buffer is ...
Vivian De Smedt's user avatar
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
  • 14.2k
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,213
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,764
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
  • 29k
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
  • 531
5 votes
Accepted

TeX/LaTeX vim fold markers options

You might want to consider adopting the vimtex plug-in, which improves support for TeX files in Vim. Among its features, it supports custom folding, which is able to recognize LaTeX blocks delimited ...
filbranden's user avatar
  • 29k
5 votes
Accepted

Fold just one line

'foldminlines' 'fml' number (default: 1) local to window {not available when compiled without the +folding feature} ...
Maxim Kim's user avatar
  • 13.6k
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
  • 50.1k
4 votes

Writing a vim fold expression for fountain.io files

OP here. I figured it out, turns out that even though I don't understand programming all too well, it was totally doable. function! FountainFolds() let thisline = getline(v:lnum) if match(...
ercfre's user avatar
  • 81
4 votes

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

While this solution is not as powerful as @user938271's one, it is far more simple and I find it sufficient for basic navigation: :set fdo-=search Setting this will make your search only find at most ...
adamency's user avatar
  • 142
4 votes

How do I undo a fold?

You don't undo a fold, you open it with zo or delete it with zd (this doesn't delete content, only suppresses the notion that there's a fold there, closable with zc). In general, try :help followed ...
Joce's user avatar
  • 161
4 votes
Accepted

Nvim where do :mkview get saved on M1 Mac?

The file of :mkview command, if used without a filename as argument, gets saved in the folder of :h viewdir. From :h :mkview: *:mkvie* *:mkview* ...
3N4N's user avatar
  • 5,764
3 votes

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

I enable folding in markdown files by using the following in my .vimrc: set foldmethod = manual set foldcolumn = 1 highlight Folded ctermbg = NONE highlight FoldColumn ctermbg = NONE let g:...
Rodrigo Pinto's user avatar

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