Answer a question

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

Answers

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.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐