visual-studio-codetextformattingsettingsindentation

How can I prevent VS Code from jumping to the bottom of a file after formatting?


How can I prevent VS Code from jumping to the bottom of a file after formatting?

I select the whole file content (using the Ctrl + A), then I format everything (using the Alt + Shift + F). After that I would expect my file to be formatted and the view not to move. The file gets formatted, but the view jumps to the bottom.

How could I prevent this jumping?

enter image description here


Solution

  • When you are doing Ctrl+A your cursor is implicitly moved to the end of the selection, hence the end of the file. Therefore, your cursor is not moved at the end by the formatting but by the selection.

    The solution is to format the whole file (with Alt+Shift+F) without selecting the content before (Ctrl + A).

    Moreover, in your case, Ctrl+A was useless because you are using the shortcut for formatting the entire document. If you only want to format a selection, the shortcut is Ctrl+K Ctrl+F.