Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

za for toggling folds does not work #1453

Closed
hk0i opened this issue Mar 30, 2017 · 8 comments
Closed

za for toggling folds does not work #1453

hk0i opened this issue Mar 30, 2017 · 8 comments

Comments

@hk0i
Copy link

hk0i commented Mar 30, 2017

Please thumbs-up 👍 this issue if it personally affects you! You can do this by clicking on the emoji-face on the top right of this post. Issues with more thumbs-up will be prioritized.


What did you do?

Place cursor over a section I want to fold then press Z, a

From vim manual:

							*za*
za		When on a closed fold: open it.  When folds are nested, you
		may have to use "za" several times.  When a count is given,
		that many closed folds are opened.
		When on an open fold: close it and set 'foldenable'.  This
		will only close one level, since using "za" again will open
		the fold.  When a count is given that many folds will be
		closed (that's not the same as repeating "za" that many
		times).

What did you expect to happen?

Section is folded on first press, and unfolded when pressing again.

What happened instead?

Nothing

Side Note:

Z, c doesn't seem to work well either, it closes the section but then expands again after a second or so.

Technical details:

  • VSCode Version: 1.10.1
  • VsCodeVim Version: 0.6.11
  • OS: OS X
@xconverge
Copy link
Member

#1004 this is part of what you are seeing

@hk0i
Copy link
Author

hk0i commented Apr 2, 2017

Is there any work around to make code folds work? What I really wanted to do was map the space key to toggle folds like I do in vim, but VSCode seems to have nothing built in for toggling folds.

@Chillee
Copy link
Member

Chillee commented May 17, 2017

I think this is currently impossible using the fold API. Even ignoring our issues with auto-expanding folds (which I am hopeful that #1004 (comment) can fix), all we have for folds is an API call for opening them and an API call for closing them. As there is no API call for telling us whether we are currently within a fold or not, we don't know which one to call.

Actually..., I think I just thought of a hack for solving this problem.

@sudowork
Copy link

I was attempting to map za to editor.unfold and zA to editor.unfoldRecursively; however, the commands don't seem to work properly. Is this an expected limitation? I know there was some discussion previously regarding limitations of the folding API, but directly invoking these commands from the command palette seem to work properly. Here's an excerpt from my settings:

    "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before": ["z", "a"],
            "after": [],
            "commands": [
                {
                    "command": "editor.unfold",
                    "args": []
                }
            ]
        },
        {
            "before": ["z", "A"],
            "after": [],
            "commands": [
                {
                    "command": "editor.unfoldRecursively",
                    "args": []
                }
            ]
        },
    ],

@shoichiaizawa
Copy link

This below is my temporary solution. I would map za to <space> if za worked as expected like what I do in the native Vim, but I kinda like these keymaps too:

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["z", "j"],
            "after": ["z", "c"]
        },
        {
            "before": ["z", "k"],
            "after": ["z", "o"]
        },
    ],

I picked zj and zk as these don't seem to work as if the native Vim (though I have never used them before):

							*zj*
zj		Move downwards to the start of the next fold.  A closed fold
		is counted as one fold.
		When a count is used, repeats the command [count] times.
		This command can be used after an |operator|.

							*zk*
zk		Move upwards to the end of the previous fold.  A closed fold
		is counted as one fold.
		When a count is used, repeats the command [count] times.
		This command can be used after an |operator|.

@J-Fields
Copy link
Member

J-Fields commented Oct 9, 2019

VSCode 1.39.0 now supports a Toggle Fold command, which we could presumably leverage for this.

@shoichiaizawa
Copy link

shoichiaizawa commented Oct 10, 2019

VSCode 1.39.0 now supports a Toggle Fold command, which we could presumably leverage for this.

Hooray 🎉

So now we can do something like this below:

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<Space>"],
            "commands": ["editor.toggleFold"],
        },
    ],

For those who wish to use za, replace "<Space>" by "z", "a" ⌨️

@J-Fields
Copy link
Member

This was fixed by #4160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants