简体   繁体   English

格式化后如何防止VS Code跳到文件底部?

[英]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?格式化后如何防止VS Code跳到文件底部?

I select the whole file content (using the Ctrl + A ), then I format everything (using the Alt + Shift + F ).我 select 整个文件内容(使用Ctrl + A ),然后我格式化所有内容(使用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?我怎样才能防止这种跳跃?

在此处输入图像描述

When you are doing Ctrl+A your cursor is implicitly moved to the end of the selection, hence the end of the file.当您执行Ctrl+A时,您的 cursor 被隐式移动到选择的末尾,因此是文件的末尾。 Therefore, your cursor is not moved at the end by the formatting but by the selection.因此,您的 cursor 最后不是由格式移动,而是由选择移动。

The solution is to format the whole file (with Alt+Shift+F ) without selecting the content before ( Ctrl + A ).解决方案是格式化整个文件(使用Alt+Shift+F )而不选择之前的内容( Ctrl + A )。

Moreover, in your case, Ctrl+A was useless because you are using the shortcut for formatting the entire document.此外,在您的情况下, Ctrl+A没用,因为您使用的是格式化整个文档的快捷方式。 If you only want to format a selection, the shortcut is Ctrl+K Ctrl+F .如果您只想格式化选择,快捷键是Ctrl+K Ctrl+F

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VS Code 光标跳到底部 - VS Code cursor jumping to bottom 格式化后防止VS代码中的新行 - Prevent new line in VS code after formatting VS Code:防止 Prettier 覆盖 Better Align 的格式 - VS Code: Prevent Prettier from overwriting formatting from Better Align 如何防止 VS Code 在 C++ 格式中将“{”放在新行上? - How to prevent VS Code from putting '{' on new line in C++ formatting? 如何防止 VS Code 在保存时恢复我的更改? - How can I prevent VS Code to revert my changes on save? 如何防止 Visual Studio Code 在格式化代码时中断长行? - How do I prevent Visual Studio Code from breaking long lines when formatting code? 自动格式化后,VS Code 如何在 Elixir 文件中保留多个空行? - How can VS Code preserve multiple blank lines in Elixir files after auto-formatting? 如何运行命令:“代码”。 安装 VS Code 后从 MacOS 终端 - How can I run the command: “code .” from MacOS terminal after VS Code installation 在 windows linux 子系统的 VS Code 中打开时,如何防止 windows 无效文件名被重命名? - How do I prevent a windows invalid file name from getting renamed when opening in VS Code in the windows linux subsystem? 生成成员时,如何防止在 C# 的 VS 代码中添加“private”访问修饰符? - How can I prevent the `private` access modifier from being added in VS Code for C# when generating members?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM