标签: indentation

Python中的条件语句

有没有办法用with语句开始一段代码,但是有条件地?

就像是:

if needs_with():
    with get_stuff() as gs:

# do nearly the same large block of stuff,
# involving gs or not, depending on needs_with()
Run Code Online (Sandbox Code Playgroud)

为了澄清,一种情况会在with语句中包含一个块,而另一种情况可能是同一个块,但不包含(即,好像它没有缩进)

最初的实验当然会给出压痕错误..

python conditional indentation with-statement conditional-statements

55
推荐指数
5
解决办法
1万
查看次数

是否可以在每个项目(或每个文件,甚至)的Xcode中设置缩进设置?

我工作的一些项目使用等于3或4个空格的tab键设置而另一个需要实际的标签.另一个根据目录混合两者.

有没有办法为每个项目设置这些设置,甚至更好,每个文件?如果没有,有人有一个聪明的方法处理这个?(除了"只记得你应该使用哪个设置并在开始编辑之前更改它")

xcode tabs indentation

54
推荐指数
4
解决办法
2万
查看次数

仅缩进段落中的第一行文本?

我有几段我想缩进,虽然只是这些段落的第一行.

我如何使用CSS或HTML仅定位第一行?

html css indentation target text-indent

53
推荐指数
5
解决办法
8万
查看次数

如何在vi或vim中多次缩进一行?

我已经找到了几个关于如何在vim中缩进多行的答案,我想知道如何使用单行并多次缩进它.实际上,我想要一个更短版本的以下命令:">>>>>>>>>>"(这是10个右括号"大于"的符号.)

vi vim indentation text-indent

50
推荐指数
5
解决办法
9061
查看次数

如何用eclipse"正确"缩进流畅的界面模式?

我刚刚为一些流畅的接口创建了一个生成器.现在我有很多代码看起来像这样:

new MyFluentInterface()
    .setFirst( "first" )
    .setSecond( "second" )
    .setThird( "third" )
    .invoke( obj );
Run Code Online (Sandbox Code Playgroud)

我喜欢上面显示的缩进,但我找不到配置eclipse以正确缩进的方法.

eclipse总是像这样缩进:

new MyFluentInterface()
.setFirst( "first" )
.setSecond( "second" )
.setThird( "third" )
.invoke( obj );
Run Code Online (Sandbox Code Playgroud)

我如何配置eclipse,以便缩进这个流畅的界面模式,如我的第一个代码示例所示?

java eclipse indentation

50
推荐指数
1
解决办法
7958
查看次数

使用Vim正确缩进HTML和PHP的缩进

我已经使用Vim一段时间了,我无法在PHP文件中使用正确的HTML缩进.

例如,我想要的是每个孩子缩进一个标签而不是它的父标签,如下所示.

<?php
if(isset($sports)) {
    //Do something
?>
<div>
    <label>Uniform Size</label>
    <ul>
        <li class="left"><label for="s" class="small">S</label><input type="radio" name="size[]" value="S" id="s" class="radio" /></li>
        <li class="left"><label for="m" class="small">M</label><input type="radio" name="size[]" value="M" id="m" class="radio" /></li>
        <li class="left"><label for="l" class="small">L</label><input type="radio" name="size[]" value="L" id="l" class="radio" /></li>
        <li class="left"><label for="xl" class="small">XL</label><input type="radio" name="size[]" value="XL" id="xl" class="radio" /></li>
    </ul>
</div>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)

使用PHP-correct-Indent脚本,代码的格式如下:

<?php
if(isset($sports)) {
    //Do something
?>
<div>
<label>Uniform Size</label>
<ul>
<li class="left"><label for="s" class="small">S</label><input type="radio" name="size[]" value="S" id="s" class="radio" /></li> …
Run Code Online (Sandbox Code Playgroud)

html php vim indentation

49
推荐指数
5
解决办法
4万
查看次数

如何用intellij中的空格序列替换文件中的所有制表符?

给定我的项目中的文件,我希望能够用空格替换文件中的所有制表符.在intellij有什么办法吗?

code-formatting indentation intellij-idea

49
推荐指数
2
解决办法
4万
查看次数

删除Vim中一行之前的所有仲裁空格

我写了一个插件来解析XML标签.标签内的内容是缩进的,当我将解析后的字符串复制到文件中时,它的内容如下:

    Example line
        This is part of the parsed line
        Thats goes one
    End of line
Run Code Online (Sandbox Code Playgroud)

我想要的是删除这些行前面的所有空格,最终文本应该是

Example line
This is part of the parsed line
Thats goes one
End of line
Run Code Online (Sandbox Code Playgroud)

我试过用=它但是它不能按照我想要的方式工作.如何用最小的击键来做到这一点?

vim indentation

48
推荐指数
4
解决办法
5万
查看次数

段落中第一行后的文本缩进

- 在楠格哈尔省Surkhrod地区的一名路透社记者说,村民们说袭击事件发生后,阿富汗警方开始向当地政府大楼投掷石块后向人群开枪.

在上面的段落中,我想使用CSS来使第一行之后的所有行自动缩进一些空格,以便每行在第一行中的 - 之后保持正确.

HTML

<p> - A Reuters reporter in Surkhrod district in Nangarhar province, where 
villagers said the raids took place, said Afghan police fired at the crowd 
after some of them started throwing stones at local government buildings.</p>
Run Code Online (Sandbox Code Playgroud)

它类似于列表位置设置为外部的列表项,但我不想使用列表.

您能想到实现这种效果的最简单方法是什么?更少的额外HTML标记会更好.

非常感谢大家.

html css indentation text-indent

47
推荐指数
2
解决办法
5万
查看次数

在Visual Studio中按Tab键选择块而不是添加缩进

我正在使用Visual Studio 2015和ReSharper 2016.2,我有这种奇怪的行为,我可能已经激活(意外).将光标放在第一个单词之前的行中时,按Tab键可以正确缩进该行:

在此输入图像描述

当光标位于行内的任何单词内部时,按Tab键可选择单词或块.

在此输入图像描述

但是期望的行为是在光标处缩进(例如,如果光标在字母r之后的单词Stream内,则将单词分成两个单词):

在此输入图像描述

有谁知道如何调用这个"功能"?它来自ReSharper吗?它可以在哪里启用或禁用?

resharper indentation keyboard-events visual-studio-2015

47
推荐指数
1
解决办法
2547
查看次数