Skip to content
Jakson Alves de Aquino edited this page May 17, 2023 · 2 revisions

Vim has several methods of folding text. To enable the syntax method of folding for R files, put in your vimrc:

let r_syntax_folding = 1

With the above option, Vim will load R files with all folds closed. If you prefer to start editing files with all folds open, put in your vimrc:

set nofoldenable

Notes:

  1. Enabling folding may slow down Vim.
  2. Folding is not a file-type plugin option. It is a feature defined in syntax/r.vim.

For other file types, if using Neovim, you may want to put in your init.vim:

set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable

And, if using init.lua:

vim.o.foldmethod = "expr"
vim.o.foldexpr = "nvim_treesitter#foldexpr()"
vim.o.foldenable = false

You should not set the option nofoldenable if you prefer all folds closed on startup.