I like to fold code in the VS Code editor, but when I fold some code blocks, they are opened when I move over them with my cursor using j / k
using the VS Code Vim extension. How can I protect my code folds from automatically opening like this?
It looks like this is an issue many people have had for a while, and the solution is to do the following (original source):
- Open up your user settings. On windows the shortcut is CTRL + ,
- Search for
vim.foldfix
and check the checkbox so the setting is set totrue
.
Alternatively, open your settings.json
file by opening the command palette (CTRL + SHIFT + P), select Preferences: Open Settings (JSON), then add the following line: "vim.foldfix": true
Now the folds should no longer automatically expand when you scroll past them with j or k.
Be aware that this is a hack because of various problems with VS Code itself that make fixing this difficult.
For people who want to prevent this without implementing the hacking way suggested by the best answer, you can simply use gj
& gk
to navigate.
Furthermore, if gj
& gk
is not convenient for you, a little mapping might help.
Note that the hacky way using vim.foldfix breaks whatever the name is for "column saving?"
In other words, if you hit a newline, the cursor will be reset to the start of the line for every future line. Instead of the desired default behavior of keeping the column position.
Use gj
and gk
like louielyl mentioned to avoid this issue
© 2022 - 2024 — McMap. All rights reserved.