本页内容

缩进文本或代码

当您输入文本或代码时,系统会根据所选的文本编辑器或代码样式偏好自动进行缩进。选中一个代码块后,按Tab 键即可对其进行缩进;按Shift+Tab 键则可减少缩进。

不检测缩进设置

打开文档时,编辑器会通过检查文档内容,尝试自动检测其使用制表符还是空格进行缩进,以及缩进宽度。如果自动检测失败,则使用默认设置。

若要关闭缩进设置的自动检测功能,请前往“Preferences ” > “Text Editor ” > “Behavior ”,并取消勾选“Auto detect ”。

“文本编辑器”首选项中“行为”选项卡的缩进设置

修复打开文件的缩进

要修复编辑器中当前打开文件的缩进设置,请在编辑器工具栏中通过“Spaces ” > “Document Settings ”或“Tabs ” > “Document Settings ”选择其他设置。

要修复编辑器中当前打开的文件的缩进:

  • 在编辑器工具栏上,选择“Spaces ”或“Tabs ”,然后选择“Auto-indent Selection ”,系统将根据当前设置自动对所选文本进行缩进。
  • 转到“Edit ” > “Advanced ”,然后选择一种缩进选项或使用键盘快捷键

缩进选项

  • 要自动缩进选中的文本,请选择“Auto-indent Selection ”或按Ctrl+I
  • 要自动格式化高亮显示的文本,请选择“Auto-format Selection ”或按Ctrl+;
  • 要调整所选段落的换行设置,请选择“Rewrap Paragraph ”或按Ctrl+E后接R
  • 要切换文本换行,请选择“Enable Text Wrapping ”或按Ctrl+E后接Ctrl+W
  • 要在编辑器中显示空白符,请选择Visualize Whitespace ,或按Ctrl+E然后按Ctrl+V
  • 要清除当前打开文件中的所有空白字符,请选择Clean Whitespace

保存文件时自动修正缩进

若要在保存文件时根据缩进设置自动修正缩进,请转至“Preferences ” > “Text Editor ” > “Behavior ” > “Clean whitespace ”,然后选择“Clean indentation ”。选择“Skip clean whitespace for file types ”可排除指定的文件类型。

“文本编辑器”偏好设置中的“行为”选项卡

在编辑器中显示空白符

要在编辑器中显示空白,请转至Preferences >Text Editor >Display >Visualize whitespace

若要显示缩进,请选择“Visualize Indent ”。若要调整显示颜色,请在“Font & Colors ”中修改编辑器配色方案中“Visual Whitespace”设置的数值。

“文本编辑器”偏好设置中的“显示”选项卡

显示右边距

若要将行长限制在特定字符数内,请在Display right margin at column 中设置字符数。若要为边距区域使用不同颜色,请选择Tint whole margin area 。取消选中该选项可将边距显示为垂直线。

若要使用可用的上下文相关边距,请选中Use context-specific margin 。然后,例如使用ClangFormatColumnLimit 选项来设置边距。

另请参阅 C++ 代码样式指定Qt Quick 代码样式行为以及键盘快捷键

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.