Search code examples
visual-studio-codevscodevim

How to prevent code-folds from automatically opening when cursor moves over them? (VSCode, vim mode)


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?


Solution

  • It looks like this is an issue many people have had for a while, and the solution is to do the following (original source):

    1. Open up your user settings. On windows the shortcut is CTRL + ,
    2. Search for vim.foldfix and check the checkbox so the setting is set to true.

    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.