如何通过多个制表位停止压缩Sublime文本?(How to stop Sublime Text from indenting by multiple tab stops?)

编程入门 行业动态 更新时间:2024-10-27 11:25:21
如何通过多个制表位停止压缩Sublime文本?(How to stop Sublime Text from indenting by multiple tab stops?)

当我在Sublime Text中有缩进的文本块时,并且在它下面有空行,按Tab将缩进到该块的级别。

每当它发生时,这仍然让我感到意外,所以我想关闭它。 我想手动将空行缩进到所需的级别。 目前,我经常需要点击一次选项卡,然后按几次退格,具体取决于先前方法结束的深度。

到目前为止,我已经尝试将auto_indent设置为false 。 这确实会停止行为......以及与自动缩进相关的所有其他操作。 我想要更有针对性的东西。

我也尝试将smart_indent设置为false 。 这在我迄今尝试过的情况下没有任何影响; 它仍然会缩进多个制表位。

试图组合一个案例。 代码的质量并不重要,只有几何。

class MyAwesomeClass: def my_okay_method(self): print(self) # point A # point B

假装评论不存在,他们仅供参考。

如果我想添加my_okay_method的行为,我会将光标放在A点行的末尾,然后按'enter'键。 我希望我的光标最终在下一个新添加的行上,它应该缩进8个空格。 编辑trim_automatic_white_space :请注意,此行为源自trim_automatic_white_space和auto_indent默认值为true 。 如果按下“enter”键,出于某种原因,光标不会缩进,出现奇怪现象。

如果我想向MyAwesomeClass添加一个新方法,我会将光标放在B点之前,添加一些空行,然后按下'tab',在A点下面两行的空行上。我希望空白行被缩进通过默认的tabstop(通常是4个空格),而不是足够远以至于它在my_okay_method的范围内 。 (当涉及循环或条件时,这会变得非常严重,因为它会进入方法的最后一个。)

When I have an indented block of text in Sublime Text, and empty lines below it, pressing tab will indent up to the level of that block.

This still surprises me every time it happens, so I'd like to turn it off. I would like to manually indent an empty line up to the desired level. Currently, I will often have to hit tab once, then hit backspace some number of times, depending on how deeply nested the preceding method ended up.

So far, I've tried setting auto_indent to false. This does stop the behavior... along with everything else related to automatic indentation. I want something more targeted.

I've also tried setting smart_indent to false. This has no effect in the cases I've tried so far; it still indents multiple tab stops.

Trying to put together an example case. Quality of the code isn't important, only the geometry.

class MyAwesomeClass: def my_okay_method(self): print(self) # point A # point B

Pretend the comments aren't there, they're just for reference.

If I wanted to add to the behavior of my_okay_method, I would position my cursor at the end of the line at point A, and press the 'enter' key. I would expect my cursor to end up on the next, newly added line, which should be indented by 8 spaces. EDIT FOR CLARITY: Note that this behavior stems from trim_automatic_white_space and auto_indent having their default value of true. If you press 'enter' and, for some reason, your cursor doesn't end up indented, something weird is happening.

If I want to add a new method to MyAwesomeClass, I would position my cursor before point B, add some blank lines, and press 'tab', on the empty line two lines below point A. I would like that blank line to be indented by the default tabstop (which is usually 4 spaces), rather than far enough to the right that it's in the scope of my_okay_method. (This gets really aggravating when loops or conditionals are involved, because it goes into the last one in the method.)

最满意答案

我创建了以下键盘映射,并将其保存到User / Default.sublime-keymap。 到目前为止,它似乎在我想要的地方工作。

编辑:我改变它特别禁用从默认键盘映射相关的映射。

[ { "keys": ["tab"], "command": "insert", "args": {"characters": "\t"}, "context": [ { "key": "setting.auto_indent", "operator": "equal", "operand": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true }, { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true } ] } ]

I created the following keymap, and saved it to User/Default.sublime-keymap. So far, it seems to work exactly where I want it to.

EDIT: I changed it to specifically disabling the relevant mapping from the default keymap.

[ { "keys": ["tab"], "command": "insert", "args": {"characters": "\t"}, "context": [ { "key": "setting.auto_indent", "operator": "equal", "operand": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true }, { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true } ] } ]

更多推荐

本文发布于:2023-07-31 02:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   文本   stop   Text   Sublime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!