Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:58:41+00:00 2026-06-16T01:58:41+00:00

Despite using Vim for a decade, sometimes I still struggle with folding. Everything in

  • 0

Despite using Vim for a decade, sometimes I still struggle with folding. Everything in this question is reproducible with no .vimrc in Vim 7.3. I am using foldmethod=marker with default foldmarkers.

Consider the following nested fold structure (using foldmethod=marker and default markers). The first column is the line number (fold0 has zero indent).

 1|{{{ fold0
 2|    {{{ fold1
 3|        {{{ fold2
 4|        }}}
 5|    }}}
 6|}}}

Suppose fold1 and fold2 are both closed and the cursor is on line 2. I can yank and put the closed fold using yyp, but the newly inserted folds are all open.

What I would like is for folds resulting from a “put” command to be closed. Alternatively, is there a convenient way to close them after the “put”? That is, from this position (with the cursor on line 6):

 1|{{{ fold0
 2|+---  4 lines: fold1----------------------------------------
 6|    {{{ fold3
 7|        {{{ fold4
 8|        }}}
 9|    }}}
10|}}}

I can use zc to close fold3, but fold 4 remains open after zo. If instead I use zC, it closes fold3 and fold 0, but fold 4 is still open when I do 2zo. This is not how I would expect recursive fold-closing to work. Is there a way to achieve zc but also recursively closing all contained folds?

The company I work for specifies that folds are defined by matching pairs without an explicit foldlevel, so solutions involving explicit foldlevel are of no use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:58:42+00:00Added an answer on June 16, 2026 at 1:58 am

    The following sequence (after your yyp) seems to do what you want:

    v% – visually select from the { under the cursor to the corresponding }

    zC – close all folds under the cursor recursively (unfortunately, this includes the outer folds that you want to remain open)

    zv – open just enough folds to display the cursor line

    zc – close the single outer fold of the new material

    Of course, you’d want to map this to some other key combination in your vimrc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Despite reading many articles (some on this board) I am still scratching my head
I'm playing with Google App Engine using the Go APIs and despite everything I've
Despite an earlier question ( asked here ), our project is constrained to using
Despite using PHP for years, I've never really learnt how to use expressions to
I have a piece of code here that does not work despite me using
I'm using xval to use client side validation in my asp.net mvc2 web-application. Despite
Despite working on EE for about 3 weeks now, believe it or not, this
This is a problem i wasn't able to solve despite extensive searches on the
I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear.
Note I am using the local vim plugin that allows me to use a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.