2

I am migrating from Vim to Emacs because I can't get Org mode to work in Vim. In Emacs is there a way to replicate Vim's marker folding so that

# Foo {{{  
foo  
# }}}

Turns into

+--  1 lines: # Foo ----

via foldmethod=marker and foldlevel=0. I have tried using vimish-fold and origami with no success. I am running Emacs GTK2 on FreeBSD 11.1 with the Evil mode plugin.

0

You can use Folding mode (folding.el) to achieve what you want. The Emacs wiki page, and the .el file have extensive documentation, but in short this is what I do to get equivalent folding in both vim and emacs.

After installing folding.el, in add the following to your ~/.emacs:

(autoload 'folding-mode          "folding" "Folding mode" t)
(autoload 'turn-off-folding-mode "folding" "Folding mode" t)
(autoload 'turn-on-folding-mode  "folding" "Folding mode" t)

Then in the files you want to enable folding, use File Variables to enable folding. For emacs and vim I add at the beginning of the file:

;; -*- mode: emacs-lisp; mode: folding; folded-file: t; -*-
;; vim: syntax=lisp: foldmethod=marker

The emacs variables enable folding mode, and sets a file to folded when you open it.

To fold a block of code/text in a file you mark it with 'comment-symbol-and-three-braces". In the case of elisp this would look like:

;;{{{ folding mode

(autoload 'folding-mode          "folding" "Folding mode" t)
(autoload 'turn-off-folding-mode "folding" "Folding mode" t)
(autoload 'turn-on-folding-mode  "folding" "Folding mode" t)

;;}}}

Folded this renders like:

;;{{{ folding mode...

And in vim renders as:

+--- 13 lines: folding mode---------

Note: in the mark constitutes the comment symbol and three braces (without a space in between). It is not just the three braces. Also, the comment comes after the mark.

There are other ways to fold files such as Hide Show and Outline mode, but this is how I get folding done for the same file in both vim and emacs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.