Prevent VSCode from unfolding code when cursor moves past folded section
Asked Answered
M

2

14

Is it possible to prevent VSCode from unfolding a folded code section if I move past it with my cursor using the arrow keys?

A common workflow I have coming from Atom is to fold parts of my code, then move my cursor down below the folded sections to get to later sections of a file. If I do this in VSCode, the folded section will unfold as soon as my cursor crosses the top of the section. I want it to move past it instead.

Here's an example:

enter image description here

I searched my prefs and Google for a setting, but couldn't find one.

Masjid answered 3/11, 2019 at 1:23 Comment(4)
Coming back to this – disabling my Vim extension seems to fix it. Still digging.Masjid
Hi Sam. Yes, if you're using the vim extension you will incur in this bug. There's an issue here and another answer on SO that you might find useful here but bottom line is that it's a known bug that still looks not 100% fixedBroderick
Thanks Nobita, I literally found this just as you submitted! The fix works great.Masjid
This is also an issue when using neovim with VSCode. See the open issue here. The most viable workaround mentioned in that issue is to set nmap j gj and nmap k gk in ~/.config/nvim/init.vim.Sells
M
17

My Google-fu failed me when I first opened this but there's plenty of discussion around it, and a fix.

The FAQ for the VSCodeVim extension also says this:

  • Moving j/k over folds opens up the folds

Try setting vim.foldfix to true. This is a hack; it works fine, but there are side effects (see issue#22276).

The fix is working great for me!! Very happy to have solved this.

Masjid answered 1/12, 2019 at 20:37 Comment(2)
It's not solved :-( I'm using <line number> + G to escape auto unfolding at the moment.Mosier
Thank you for this, it's been driving me crazy. Can't wait till there's an official fix; until then I'm glad this at least fixes the k/j navigation.Clarissaclarisse
T
0

Use this config:

"vim.normalModeKeyBindings": [
    {
      "before": ["j"],
      "after": ["g", "j"]
    },
    {
      "before": ["k"],
      "after": ["g", "k"]
    }
  ],
Toast answered 11/5 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.