Stack Undefined
Stack Undefined

Reputation: 1330

VS code moves the cursor to start of next line when pressing enter key

Instead of respecting the current block's indentation level, the cursor moves to the start of the new line when pressing the enter key.

          {
             "name": "foo",
|
          }

The cursor should jump to the same level as the name key.

This happens even with the empty curly brackets.

          {|}

Hit enter

          {
|} 

There doesn't seem to be a setting that can be set so the cursor only jumps to the current indentation level.

Upvotes: 7

Views: 5165

Answers (5)

JaffXXI
JaffXXI

Reputation: 85

It can also happen if you're using the yapf extension for formatting. Make sure you have "editor.formatOnType": false.

"[python]": {
"editor.formatOnSaveMode": "file",
"editor.formatOnSave": true,
"editor.defaultFormatter": "eeyore.yapf",
"editor.formatOnType": false

}

Upvotes: 1

Dusan
Dusan

Reputation: 21

I found that editor.language.brackets was set to [] in Settings.json. Remove it, and should work as expected.

Upvotes: 2

Slavi
Slavi

Reputation: 171

This issue can also happen if you have "files.autoSave": "afterDelay". Saving the file moves your cursor at the beginning of the line, if line is empty.

Upvotes: 1

For me, the default value of Editor:auto.indent was "full", but I still experienced the issue.
To fix, I needed to re-save Settings (after changing the option twice) to make it work in C#.

Option illustration in VS Code

Upvotes: 4

Stack Undefined
Stack Undefined

Reputation: 1330

I kind of fixed this issue by setting the Editor:auto.indent to "full".

Upvotes: 2

Related Questions