13

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.

20

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.

  • I get error message E350: Cannot create fold with current 'foldmethod' after pressing keys zf. – niekas Apr 30 '15 at 6:04
  • 1
    @niekas: Set foldmethod to manual first. – lcd047 Apr 30 '15 at 6:06
  • @lcd047 Thats great! Thank you very much. @200_success should add :set foldmethod=manual to his answer. – niekas Apr 30 '15 at 6:09
  • 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 '15 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. – 200_success Apr 30 '15 at 6:56

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.