VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.84k stars 1.31k forks source link

Indent using `==` or `=` on visual selection does not properly indent #4205

Open kschaab opened 4 years ago

kschaab commented 4 years ago

Describe the bug I have been able to reliably reproduce this in json files, but not in other languages. Using == or = on visual selection does not always indent properly.

To Reproduce In JSON if you have an improperly indented line and hit == it will not indent. However, let's say the previous line is indented properly, if you hit 2== from that line then the line that would not indent will now indent. It also works properly in select mode if there are lines that are indented properly in the selection.

{
    "naut.auto-install": true,
"typescript.preferences.quoteStyle": "single",
    "typescript.referencesCodeLens.enabled": true
}

== on line 3 does nothing 2== from line 2 indents line 3 as expected = on 2 selected with 3 works as expected = on 3 and 4 selected deindents 4 (not expected)

Expected behavior == is contextual and should indent based on surrounding code.

pseyfert commented 4 years ago

let me add (background info: out of habit I use =j instead of ==. =j should apply "the correct indentation to the current and the following line, such that they match the previous line)

=j on line 3 in vim would indent line 3 (and it would indent 4 if there was anything to be done with line 4)

=j with vscodevim leaves line 3 and deindents line 4.

ph0ngp commented 4 years ago

@kschaab try putting this into your keybindings.json

    {
        "key": "= =",
        "command": "editor.action.reindentselectedlines",
        "when": "editorTextFocus && editorLangId == jsonc && vim.active && vim.mode == 'Normal'"
    }
kschaab commented 4 years ago

Excellent work around, thanks!

On Wed, Aug 19, 2020 at 3:10 AM Phong notifications@github.com wrote:

@kschaab https://github.com/kschaab try putting this into your keybindings.json

{
    "key": "= =",
    "command": "editor.action.reindentlines",
    "when": "editorTextFocus && editorLangId == jsonc && vim.active && vim.mode == 'Normal'"
}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/VSCodeVim/Vim/issues/4205#issuecomment-676080117, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABX5KBLZ3JKRAD4X5M6KIOTSBOQIXANCNFSM4JDQQT3A .