PyCharm:如何跳过关闭括号/括号/括号?

时间:2011-07-01 07:19:23

标签: python ide pycharm

我无法让自动缩进正常工作,除非我使用自动关闭大括号等(我不喜欢),并且我看不到允许跳过/跳过的选项。

Eclipse有一个配置选项,默认情况下Visual Studio不会自动关闭所有内容,而是在手动输入右括号(我更喜欢)之后格式化代码块。

当然除了一直到“结束”键之外还有什么东西?

5 个答案:

答案 0 :(得分:9)

按Ctrl-Shift-Enter键关闭当前行上缺少的大括号(如果有),添加缺少的冒号(如果缺少)并将插入符号放入下一行正确缩进的位置。

答案 1 :(得分:1)

一所大学告诉我一个解决方案:

首先输入:

def test_foo(
输入self)

后,PyCharm会立即插入(

当前状态:^表示光标位置:

def test_foo(self^):

只需输入):并点击ENTER即可,您就在下一行。

由于我用十根手指Ctrl-Shift-Enter打字,因此在这种常见的编辑操作中不适合我。

答案 2 :(得分:1)

Shift + Enter 将跳过补全,并将您带到下一行。

Ctrl +] 将跳到当前元素的末尾。

在大多数情况下,这似乎可以跳过过去的自动填充。我发现它是最通用的选项。

Ctrl + [将使您跳至所位于的任何代码块的开头。

如前所述, Ctrl + Shift + Enter 将添加您可能需要的所有其他自动完成内容,并放到新行中。

答案 3 :(得分:0)

Why do you dislike the auto-closing brackets? They do not disturb anyone, see:
^ specifies the cursor position

method([a, {b: c^}])
behaves as if no brackets were there if you insert new brackets!

insert a '}':
method([a, {b: c}^])
now insert a ']':
method([a, {b: c}]^)
now insert a ')':
method([a, {b: c}])^

et voila! From a users point of view, if you typed blindly, you can not tell from what you see now if the auto-closing brackets were inserted or not.

Or simply: keep the closing brackets on. IntelliJ did a great work on a lot of small things we want to have intuitively.

答案 4 :(得分:-5)

在设置菜单中花了很长时间后,我在很多方面得到了类似于Eclipse的配置 - 包括在启用“插入对”时处理大括号/括号/括号的方式;确切的组合是无法联系的。

我不相信IDE在进入结束括号时具有涉及自动格式化的确切功能(类似于Visual Studio),但如果有人发现某种方式,我很乐意标记出与我不同的答案。