Vim icon indicating copy to clipboard operation
Vim copied to clipboard

`<C-d>` or `<C-u>` doesn't work when opening a file with imports folded by default.

Open JannatinNaimX3 opened this issue 3 years ago • 3 comments

If a file contains folded imports the <C-d> and <C-u> keys don't work.

Steps to reproduce the behavior:

  1. Open a JavaScript file with imports and fold them.
  2. Close file and open it again.
  3. Try pressing <C-d>.

Expected behavior: It's supposed to take you down half a page but those keys don't work. It only starts working if you go to the top of the file and hit j a few times to unfold the lines.

  • Extension (VsCodeVim) version: 1.23.1
  • VSCode version: 1.69
  • OS: MacOS

JannatinNaimX3 avatar Jul 16 '22 23:07 JannatinNaimX3

Just realize that I have very similar problem and also found my solution.

Settings:

    "vim.handleKeys": {
        "<C-d>": false,
        "<C-u>": false,
    },

Shortcuts:

    // fix <C-d> and <C-u>
    {
        "key": "ctrl+d",
        "command": "cursorMove",
        "args": {
            "to": "down",
            "by": "line",
            "value": 34
        },
    },
    {
        "key": "ctrl+u",
        "command": "cursorMove",
        "args": {
            "to": "up",
            "by": "line",
            "value": 34
        },
    },

JimmyZJX avatar Jul 26 '22 02:07 JimmyZJX

That's a cool solution, I was having some inconsistencies with vim handling those two as well, this makes same behaviour but native. Cheers

lakardion avatar Aug 06 '22 19:08 lakardion

I was excited about your solution at first but found out that could not use it when I was in visual mode (sometimes I like to select big chunks with C-d and C-u.

An alternative to this is to create vim keybindings for the corresponding modes:

//settings.json
{
//...
  "vim.normalModeKeyBindingsNonRecursive": [
     {
      "before": ["<C-d>"],
      "after": ["2", "0", "j"]
    },
    {
      "before": ["<C-u>"],
      "after": ["2", "0", "k"]
    }
  ],
  "vim.visualModeKeyBindings": [
    {
      "before": ["<C-d>"],
      "after": ["2", "0", "j"]
    },
    {
      "before": ["<C-u>"],
      "after": ["2", "0", "k"]
    }
  ]
//...
}

EDIT: misinstructed about vim.handleKeys. <C-d> and <C-u> should be managed by vim Stole this from #1348

lakardion avatar Aug 09 '22 13:08 lakardion

Doesn't have to be the imports that are folded for me. When writing jest tests, I can fold a describe block and this issue happens too.

dyllandry avatar Oct 05 '22 18:10 dyllandry

The same problem happens when I fold any part of any file.

ElSamhaa avatar Jul 14 '23 17:07 ElSamhaa