How can I prevent VS Code from jumping to the bottom of a file after formatting?
Solution 1:
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
.