当我使用IntelliJ的功能“使用行注释注释”时,它会在所选行的最开头放置两个斜杠。正斜杠不会与其余代码一起缩进。如何在放置正斜杠时使IntelliJ服从行缩进?
示例代码:
if (something) {
bar();
}
在第2行使用IntelliJ的评论功能导致:
if (something) {
// bar();
}
我想要的是什么:
if (something) {
// bar();
}
答案 0 :(得分:60)
转到 def edit
@category = Category.friendly.find(params[:category_id])
@post = Post.find(params[:id])
@post.build_location if @post.location.nil?
end
并取消选中“在第一列排行评论”选项。
2016年10月更新@henrebotha评论:
截至目前,在其下方还有一个附加选项,即“在评论开始时添加空格”,因此现在支持此功能。
答案 1 :(得分:3)
您可以在Code Generation中进行设置。
答案 2 :(得分:2)
在最新版本中,该设置称为:
Comment at first column
只需在设置窗口中搜索它,然后转到Editor -> Code Style -> Your language
。
答案 3 :(得分:1)
对于那些正在寻找如何为Scala做到这一点的人,<Shell x:Name="theShell"
x:Class="TailwindTraders.Mobile.Features.Shell.TheShell"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:home="clr-namespace:TailwindTraders.Mobile.Features.Home"
xmlns:local="clr-namespace:TailwindTraders.Mobile.Features.Shell"
xmlns:productcategory="clr-namespace:TailwindTraders.Mobile.Features.Product.Category"
Title="Tailwind Traders"
Route="tailwindtraders"
RouteHost="www.microsoft.com"
RouteScheme="http"
FlyoutBackgroundColor="Red"
>
配置位于Line comment at first column
标签中,而不是File > Settings > Editor > Code Style > Scala > Other
,与可接受的答案一样
答案 4 :(得分:0)
以防万一,在共享代码风格的环境中,如果选中Settings > Editor > Code Style > Enable EditorConfig support
,这可能对您不起作用。
您的共享样式可能会覆盖它。您将不得不与项目时尚警察讨论此事。
答案 5 :(得分:0)
我建议使用EditorConfig。因为通过在项目中拥有.editorconf
文件,您可以impose
的编码风格,这对于您可能与他人共同开发的项目非常重要。
它将递归搜索到项目的父目录,并以分层方式应用样式设置。 因此,放置特定项目会覆盖您的某些内容,例如全局设置。
要么创建一个.editorconf文件,要么甚至更好地右键单击侧边栏上的项目,然后选择:
这将创建文件并填充所有选项(特定于智能的选项以ij
开头),因此您可以根据需要进行修改。
ij_java_block_comment_at_first_column = false
ij_java_line_comment_add_space = true