Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for VSCodeVim code folding issue (solves #1004) #4517

Open
aerosayan opened this issue Jan 27, 2020 · 10 comments
Open

Solution for VSCodeVim code folding issue (solves #1004) #4517

aerosayan opened this issue Jan 27, 2020 · 10 comments

Comments

@aerosayan
Copy link

Solves->
#1004

Introduction->
First of all, thank you for this amazing plugin.
Without a vim plugin, I wouldn't be using vscode.

Thank you very much for your hard work.

Problem ->
vscode vim folding has been an issue for a lot of time and, AFAIK vscode devs havn't fixed the issue and it seems they don't plan to provide the required API to solve these issues.

This has been probably the most requested feature ( #1004 ) for VSCodeVim but due to the negligence of support from core vscode team, I was going to leave vscode behind, out of frustration.

Discussion ->
But I didn't want to leave vscode.

So I came up with a solution myself.

I don't know if it is the "best" solution. It works for me. And I plan to continue using it.

I'm sharing here in hope that if someone else is facing the same problem, they are able to solve the issue and enjoy using vscode.

I'm not noticing any performance degradation due to using this fix, but it's a dirty fix nonetheless.

Use->

  • Setup the macros as shown in solution section.
  • Use alt+j to move down.
  • Use alt+k to move up.

Solution ->
I used macros to setup alternative ways to move up and down which didn't have the code folding issue.

I downloaded this macro plugin : <<< LINK >>>

I included the following setting into settings.json

"macros": {
    "vimAltDown" : [
        "toggleVim",
        "cursorDown",
        "toggleVim"
    ],
    "vimAltUp" : [
        "toggleVim",
        "cursorUp",
        "toggleVim"
    ]
}

I added the following to keybindings.json

{
    "command": "macros.vimAltDown",
    "key": "alt+j"
},
{
    "command": "macros.vimAltUp",
    "key": "alt+k"
}

How it works ->
I used the macro library to setup proper macros that would toggle out of vim mode, move the cursor down or up and toggle vim on again.

When vim mode is toggled off, the cursor can move up and down without expanding the code folds.

Request->
If this is suitable for your needs, could you please include the solution in a more official way?

Thanks

@aerosayan
Copy link
Author

BUG

Using this method, the cursor goes through the code, but for some reason now, the cursor resets back to line 1 or 2 of the file.

Maybe someone who knows the system well could look into it?

Thanks.

@aerosayan
Copy link
Author

BUG

Using this method, the cursor goes through the code, but for some reason now, the cursor resets back to line 1 or 2 of the file.

Maybe someone who knows the system well could look into it?

Thanks.

Found a temporary fix.

After using alt+j or alt+k to scroll through the code, press escape once.

Then go on using j and k to scroll through your code.

Pressing escape somehow ensures that the cursor remains at the desired position and doesn't jump to line 1 or 2 of the code.

@aerosayan
Copy link
Author

UPDATE -> GOOD NEWS !

I went over the code and wasn't happy with the rapid vim toggles.
I removed them and kept the move cursor commands.

It is still working.

And this doesn't have the bug where the cursor jumps to line 2 or 1.

Now settings.json just needs :

"macros": {
    "vimAltDown" : [
        "cursorDown"
    ],
    "vimAltUp" : [
        "cursorUp"
    ]
}

@pianocomposer321
Copy link

Which means you don't need the macros!

@aerosayan
Copy link
Author

Which means you don't need the macros!

No.
The macros are still required in this implementation.

What is different in this macro is that it seems to work without rapidly toggling vim on and off.

cursorUp and cursorDown are only used.

But I get where you are coming from. It might be possible to just remap the k and j keys to cursorUp and cursorDown commands.

@pianocomposer321
Copy link

That's exactly what I meant - the whole point of the macros is to do more than one command by calling just one custom command. A macro that calls only one command is pointless. Instead, you could do:

"vim.normalModeKeybindingsNonRecursive": [
    {
        "before": "j",
        "commands": "cursorDown"
    },
    {
        "before": "k",
        "commands": "cursorUp"
    }
]

@aerosayan
Copy link
Author

That's exactly what I meant - the whole point of the macros is to do more than one command by calling just one custom command. A macro that calls only one command is pointless. Instead, you could do:

"vim.normalModeKeybindingsNonRecursive": [
    {
        "before": "j",
        "commands": "cursorDown"
    },
    {
        "before": "k",
        "commands": "cursorUp"
    }
]

Love this.
Did you see the preferred results on your side?
I will test if it works out on my end.

@pianocomposer321
Copy link

pianocomposer321 commented Feb 29, 2020

Yes. I have been using it for a while. It also solves the lag that I had been experiencing. The one caveat is that it breaks counts like 10j for j and k. I don't use counts for j and k though, so it worked for me.

@CodeMonkeyG
Copy link

Was having the same issues and was brought to this thread. Took the provided solution and had to modify it for what I assume is a later version of the extension.

"vim.normalModeKeyBindingsNonRecursive": [
    {
        "before": ["j"],
        "commands": ["cursorDown"]
    },
    {
        "before": ["k"],
        "commands": ["cursorUp"]
    }
]

@kubil6y
Copy link

kubil6y commented Dec 27, 2022

folding fix is terrible. just use these to step over folded places.

    {
        "key": "alt+j",
        "command": "cursorDown"
    },
    {
        "key": "alt+k",
        "command": "cursorUp"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants