VSCodeVim / VSCodeVim/Vim

Folding: `zx` for updating folds/collapsing all other folds

Open
#5,423 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement
Dominant language
TypeScript
Stars
15.2k
Forks
1.5k
Avg merge
3d 18h
Merged PRs (30d)
6

Description

Is your feature request related to a problem? Please describe.
I would often like to collapse all folds except for the one at the cursor position.

Describe the solution you'd like
From :help folding in vim: "It may happen that folds are not updated properly. You can use zx or zX to force updating folds."

The effect of this is to collapse all folds that the cursor position is not a part of.
E.g.,

int main(int argc, char *argv[])
{
  if (argc > 1)
  {
    std::cout << argc << std::endl; // <- cursor position
    if (argc > 2)
    {
      call_some_function();
    }
  }
  if (argc > 1)
  {
    std::cout << argc << std::endl;
    if (argc > 2)
    {
      call_some_function();
    }
  }
  return 0;
}

would collapse to

int main(int argc, char *argv[])
{
  if (argc > 1)
  {
    std::cout << argc << std::endl; // <- cursor position
    if (argc > 2)
+----  3 lines: {················································································
  }
  if (argc > 1)
+---  7 lines: {·················································································
  return 0;
}

Describe alternatives you've considered

  • Using ctrl-k ctrl-1 through ctrl-k ctrl-7 approximates this up to a limit, but involves 14 keystrokes and stops at fold level 7.
  • Using zM then <line number>G and <column number>| essentially performs the desired operation, but involves 6-10 keystrokes on average and requires remembering the line and column numbers of the cursor position.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the requested zx behavior with the existing Ctrl-K fold commands and zM behavior in VSCodeVim. Implement folding that preserves the cursor's containing folds while collapsing others, then verify it against the C++ example and the stated alternatives.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.