Vim: Folded code unfolds if you spend some (unknown number) of ms idle in a fold

  • Click thumbs-up šŸ‘ on this issue if you want it!
  • Click confused šŸ˜• on this issue if not having it makes VSCodeVim unusable.

The VSCodeVim team prioritizes issues based on reaction count.


What did you do?

Scrolled through folded code once with the j key held down, another time pressing it over and over.

What did you expect to happen?

Folded lines were skipped.

What happened instead?

Cursor did not skip the folded lines (watch the line numbers in the gif).

Technical details:

  • VSCode Version: 1.6.1
  • VsCodeVim Version: 0.4.0
  • OS: macOS Sierra (10.12)

vscode-vim-skip-folds

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 765
  • Comments: 73 (18 by maintainers)

Commits related to this issue

Most upvoted comments

We just pushed out a new version, so enable vim.foldfix and tell us what you think!

Itā€™s a hack and not a proper solution to this problem, so weā€™ll probably leave this issue open for now.

+1 for this. Having my folds open while Iā€™m navigating is quite frustrating. I find myself having to use my mouse to reposition my cursor, which should make all of us sad.

+1 comments arenā€™t going to do anything but annoy the repo owners. Please use the šŸ‘ reaction on the original post instead. Be kind to repo owners and other subscribed users.

šŸ˜ƒ Itā€™s okay. We generally use thumbs up as a measure of importance, but the extra signal we get from people who were so bothered they had to come and leave a comment is a little useful too. Weā€™re definitely aware this one is painful - weā€™ll try to fix it as soon as we can!

I polished up my fix over here: https://github.com/VSCodeVim/Vim/pull/1552

It does some hackish stuff, but it seems to work great for me. Hereā€™s a pretty bad demo:

test

I can confirm what @pizzooid has noted, that gj and gk correctly step over folded sections even without vim.foldFix enabled. If you want to use this as a workaround, you can add the following to your settings JSON:

"vim.normalModeKeyBindings": [
    {
        "before": ["j"],
        "after": ["g", "j"]
    },
    {
        "before": ["k"],
        "after": ["g", "k"]
    },
    {
        "before": ["$"],
        "after": ["g", "$"]
    },
    {
        "before": ["^"],
        "after": ["g", "$"]
    }
],
"vim.visualModeKeyBindings": [
    {
        "before": ["j"],
        "after": ["g", "j"]
    },
    {
        "before": ["k"],
        "after": ["g", "k"]
    },
    {
        "before": ["$"],
        "after": ["g", "$"]
    },
    {
        "before": ["^"],
        "after": ["g", "$"]
    }
]

Would it make sense to make this the default behavior for the plugin? Or would this be too unexpected for folks who are used to traditional vim behavior for j and k?


Update 2019-02-26: Iā€™ve updated the settings to handle the $ and ^ movements correctly.

I agree with @Chillee . Maybe some one should reopen the issue with vscode? It has been a couple of years maybe it can be prioritized.

sorry to say, but this makes the extension useless for me.

greetzā€¦

I have only "vim.foldfix": true, in my settings and it works fine, both with j, k and upArrow, downArrow.

with foldfix it works with j/k, but

  • ctrl-u/ctrl-d
  • {/} (shift-[/shift-])
  • 10-/10+ (relative jump)

still open collapsed fold.

vscode just close Microsoft/vscode#22276, they will not consider this feature in the next 6-12 months roadmap.

Iā€™ve created a new issue about it, go and vote! šŸ˜‰

https://github.com/microsoft/vscode/issues/81498

As an alternative to CTRL-u & CTRL-d Iā€™ve been using H & L which do not break the fold.

To add on this, you can use the following settings to make it more jump like:

"vim.normalModeKeyBindings": [
      {
        "before": ["<C-u>"],
        "after": ["H", "z", "z"]
      },
      {
        "before": ["<C-d>"],
        "after": ["L", "z", "z"]
      }
]

Its been almost two years since microsoft/vscode#22276, maybe itā€™s worth to try again?

after set foldfix, j/k works fine to skip fold, but ctrl-u/ctrl-d still break the fold.

We just pushed out a new version, so enable vim.foldfix and tell us what you think!

Itā€™s a hack and not a proper solution to this problem, so weā€™ll probably leave this issue open for now.

Can you make this a default option, not everyone know about this, I just want to open an issue then when I search again on google, finally I landed on this, or at least the issue should be pinned down.

Thank you for brigging the foldfix, I really frustated with how the cursor open all fold

with foldfix it works with j/k, but

  • ctrl-u/ctrl-d
  • {/} (shift-[/shift-])
  • 10-/10+ (relative jump)

still open collapsed fold.

As an alternative to CTRL-u & CTRL-d Iā€™ve been using H & L which do not break the fold.

I can confirm what @pizzooid has noted, that gj and gk correctly step over folded sections even without vim.foldFix enabled. If you want to use this as a workaround, you can add the following to your settings JSON:

"vim.normalModeKeyBindings": [
    {
        "before": ["j"],
        "after": ["g", "j"]
    },
    {
        "before": ["k"],
        "after": ["g", "k"]
    },
    {
        "before": ["$"],
        "after": ["g", "$"]
    },
    {
        "before": ["^"],
        "after": ["g", "$"]
    }
],
"vim.visualModeKeyBindings": [
    {
        "before": ["j"],
        "after": ["g", "j"]
    },
    {
        "before": ["k"],
        "after": ["g", "k"]
    },
    {
        "before": ["$"],
        "after": ["g", "$"]
    },
    {
        "before": ["^"],
        "after": ["g", "$"]
    }
]

Would it make sense to make this the default behavior for the plugin? Or would this be too unexpected for folks who are used to traditional vim behavior for j and k?

Update 2019-02-26: Iā€™ve updated the settings to handle the $ and ^ movements correctly.

I would suggest to use vim.normalModeKeyBindingsNonRecursive and vim.visualModeKeyBindingsNonRecursive to make sure we avoid nasty recursive loops. Other than that, I can only confirm this is a working workaround! Cheers! šŸ˜ƒ

@gschintgen Unluckily, the best solution is to not set foldfix to true for most people šŸ˜•

I would say ā€œpartially fixedā€. I can navigate over folds but if i initiate a fold from inside from anywhere but the top of of the folding block then it immediately unfolds. This is certainly better than before though. VSCode v1.12.2 Vim v0.8.4

I just found noticed that gj works properly without vim.foldfix enabled. Is that because of the fix, or would that be a different method for building foldFix?

@Phrohdoh for example 25gg will take you to 25th line not the beginning i meant end of the block by last line

@desprit The issue isnā€™t closed. As far as I know (itā€™s been a while since Iā€™ve looked into this very closely), thereā€™s nothing we can do unless VSCode expands its API to give us more information about folded regions.

The j to gj bind is undesireable, IMO. gj wonā€™t ā€œrememberā€ which column you were at when pass an empty line.

gj will result in: line 1: column 45 line 2: column 0 (empty line) line 3: column 0

j will result in: line 1: column 45 line 2: column 0 (empty line) line 3: column 45

With foldfix enabled, relative jumping is no longer instant, and it is inaccurate when jumping over a fold.

there was a response here from a maintainer of vscode suggesting a solution to this.

Wouldnā€™t a good solution to this be a vscode api where cursorDown just has a new boolean argument that is something like openFolds: false. It seems like they are open to that

The biggest downside in theory is that it deviates from the expected vim behavior. gj/gk are the commands for move the cursor around wrapped lines, which means if youā€™re expecting to jump over wrapped lines the same way it jumps over folded lines, then itā€™ll be a bit confusing (since it effectively jumps into the middle of a wrapped line). This behavior is acceptable for me, but might be undesirable for vim purists (though tbh I also donā€™t know how the real vim handles folding šŸ¤·ā€ā™€ļø).

The other issue is that Iā€™m not sure those keybindings are quite complete. For example $/^ arenā€™t modified, so they still treat wrapped lines like a single line, while j/k now treat wrapped lines as multiple different lines. Iā€™ve also noticed that some cursor motions while working with wrapped lines donā€™t quite work as expected, though I havenā€™t yet figured out whatā€™s going on there. Iā€™ll update my comment if I find any other improvements šŸ™‚

IDK, why VSCode team helping us out on this problem. There are more than 6M+ VIM users & Iā€™m one of them cry, We love this extension but So helpless, hopeless.

PRs welcome

Hi, itā€™s a pity that I canā€™t really use code folding due to this issue.

I tried foldfix=true (which seems to work fine), but unfortunately it leads to very laggy behaviour: If I keep j or k pressed in order to move up or down in a source file, the cursor continues to move down or up even after I let go of the movement key. The cursor is playing catch-up.

This is 100% reproducible on my machine (4th gen. mobile i7) and even happens when I donā€™t have any folded code parts!

Do note that even though my comment may sound negative, Iā€™m very grateful for the active development of this extension!

@rogersachan Thereā€™s been a significant amount of discussion on the VSCode repo, and itā€™s a very nontrivial task. Take a look at https://github.com/Microsoft/vscode/issues/22276

@meherranjan I agree. Itā€™s an ugly hack, which is why itā€™s not enabled by default and why this issue remains open.

Good catch, @zwing99! Iā€™m seeing the same thing on my end, as well.

Oops now Iā€™m spamming (I didnā€™t mean to close this).

+1 for fixing this asap