23

How can I fold and unfold lines selected in visual mode?

Lets say I have three paragraphs and I want to fold the first or last two into one line:

Test
====
Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos
de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias..

Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos
de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias..

Lorem Ipsum es simplemente el texto de relleno de las imprentas y archivos
de texto. Lorem Ipsum ha sido el texto de relleno estándar de las industrias..

za folds only one paragraph.

1 Answer 1

40

You can press V to go into Visual Line mode, select the lines to be folded, then zf to make a manual fold. You'll need to :set foldmethod=manual if it isn't already set.

You can open the fold with zo, or delete the fold with zd.

6
  • 1
    I get error message E350: Cannot create fold with current 'foldmethod' after pressing keys zf.
    – niekas
    Apr 30, 2015 at 6:04
  • 1
    @niekas: Set foldmethod to manual first.
    – lcd047
    Apr 30, 2015 at 6:06
  • I got one more problem. I have .rst file with section Test\n====. When I select several paragraphs of this section and press zf all section gets folded instead of the selected paragraphs. How do I turn this automation off?
    – niekas
    Apr 30, 2015 at 6:25
  • 1
    If a new fold you are trying to create partially overlaps with an existing open fold, then closing the new fold will cause overlapping folds to close too. You may need to delete some folds using zd first. Apr 30, 2015 at 6:56
  • May I ask, after using zf to fold a few sections, then moved the cursor out of those sections, why I cannot use zr to unfold all sections? Thank you.
    – midnite
    May 20, 2022 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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