Sublimetext2 在一定数量的字符后自动打断注释

Sublimetext2 在一定数量的字符后自动打断注释,sublimetext2,Sublimetext2,是否可以突出显示一个较大的注释块,并在一定长度后自动插入打断符 简单示例 # This is a super long message that has too much information in it. Although inline comments are cool, this sentence should not be this long. 之后 # This is a super long message that has too much information in it.

是否可以突出显示一个较大的注释块,并在一定长度后自动插入打断符

简单示例

# This is a super long message that has too much information in it. Although inline comments are cool, this sentence should not be this long.
之后

# This is a super long message that has too much information in it.
# Although inline comments are  cool, this sentence should not be this
# long.

对!!而且它比这个答案的长度所暗示的要简单

背景 有一个名为
wrap_lines
的命令,它能够精确地显示您想要的内容<代码>换行在
Packages/Default/paration.py
第112行中定义,并在以下位置稀疏记录:

换行
包装线。默认情况下,它在第一个标尺的列处换行

  • 宽度[Int]:指定应在其中换行的列
wrap\u行
已经可以通过
Edit->wrap
菜单中的项目访问。可以选择将光标位于第70、78、80、100和120列的段落以及第一个标尺包裹起来。默认情况下,标尺处的
换行段落
在Windows上映射到
Alt+Q
,在OSX上映射到
Super+Alt+Q

与统治者合作 我说的第一把尺子是什么意思?您可以通过
查看->标尺
调用标尺,但如果您希望屏幕上有多个标尺(或者希望标尺是书面的),您可以将定义标尺的JSON整数数组添加到任何
文件中。例如,我添加到用户首选项文件中的数组如下所示:

"rulers":
[
    79,
    80,
    72
],
多亏了第一个标尺规则,
Alt+Q
将在79列标记处换行,长度超过79个字符,即使在第72列“之前”有一个标尺。“第一个标尺”不是指最左边的标尺,而是指第一个定义的标尺。如果我像下面那样将
80、
移动到索引0,那么行将换行到80列。同样适用于
72

"rulers":
[
    80,
    79,
    72
],
使用密钥绑定 你说统治者是为弱者服务的?您还可以编写一个新的换行符,在您选择的列处换行!只需将类似的内容添加到您的
首选项->键绑定–用户文件中:

{ "keys": ["alt+q"], "command": "wrap_lines", "args": {"width": 80} },
删除
args
对象将改为在第一个标尺处换行,就像
在标尺处换行段落
命令那样<代码>在标尺处换行段落
的定义实际上与默认Windows键映射文件中的定义相同:

{ "keys": ["alt+q"], "command": "wrap_lines" },
警告
wrap_lines
命令的一个优点(在某些情况下,也是最坏的)是,它将检测以行开头的任何非字母数字字符序列,并在换行时将其复制。写评论很好,因为您的示例所建议的行为确实发生了:

# This is a super long message that has too much information in it. Although inline comments are cool, this sentence should not be this long, because having to scroll to the right to finish reading a comment is really annoying!
变成:

# This is a super long message that has too much information in it.
# Although inline comments are cool, this sentence should not be this
# long, because having to scroll to the right to finish reading a
# comment is really annoying!
# Hey, this header isn't really there!

Be careful with what starts the original line. Also, the
`wrap_lines` command **targets the entire paragraph**, not just
the current line.
但是,如果行恰好以任何其他符号开头,比如引号的开头,那么升华文本也不知道如何更好地包装这些符号。因此:

# "This is a super long message that has too much information in it. Although inline comments are cool, this sentence should not be this long, because having to scroll to the right to finish reading a comment is really annoying!"
变成了我们可能不想要的:

# "This is a super long message that has too much information in it.
# "Although inline comments are cool, this sentence should not be this
# "long, because having to scroll to the right to finish reading a
# "comment is really annoying!"
这是一个好主意,要小心什么开始你原来的路线。另外,
wrap_lines
命令将光标触摸的整个段落作为目标,而不仅仅是当前行,令人惊讶的是,也不仅仅是工作选择。这意味着您可以在新包装的一系列行上再次使用该命令,以在不同的列中重新包装这些行,但如果在标记中对齐标题下的段落,也可能会包装一些您不喜欢的行:

# Hey, this header isn't really there!
Be careful with what starts the original line. Also, the `wrap_lines` command **targets the entire paragraph**, not just the current line.
如果该命令在该文本块中的任何位置被激活,您将得到以下结果:

# Hey, this header isn't really there! Be careful with what starts the
original line. Also, the `wrap_lines` command **targets the entire
paragraph**, not just the current line.
通过巧妙地使用空格,可以避免此类问题;标题和段落之间的另一条空行将修复包装,因此:

# Hey, this header isn't really there!

Be careful with what starts the original line. Also, the `wrap_lines` command **targets the entire paragraph**, not just the current line.
变成:

# This is a super long message that has too much information in it.
# Although inline comments are cool, this sentence should not be this
# long, because having to scroll to the right to finish reading a
# comment is really annoying!
# Hey, this header isn't really there!

Be careful with what starts the original line. Also, the
`wrap_lines` command **targets the entire paragraph**, not just
the current line.

由于操作如此之快,您应该不会有太多的麻烦来追踪您遇到的任何错误的原因,重新开始,并创造性地避免它们。升华文本通常不会在代码中将注释和非注释混合在一起时遇到任何问题,因此,如果幸运的话,您将永远不必担心它

您好,我遇到了这个解决方案,并用Supreme Text 3进行了尝试,效果非常好。如果我在python docstring上使用通常的Alt+q,它将完成非常理想的功能:

  • 将范围限制为docstring
  • 将正确完成开头和结尾“”或“”
它涉及修改默认包中的一个命令。请参见此处

在升华文本3中,默认包位于\Packages\default.Sublime-package下。您必须解压缩它,并找到文件paragration.py。将(仅)此文件放在用户包目录下,例如。\Data\Packages\default\下,因此此文件现在覆盖默认包的paragration.py

感谢原作者Chris Beaven(SmileyChris)。

在SublimiteText3中(以及任何支持正则表达式的早期版本,即所有版本):

以下是每48个字符插入一个换行符的搜索/替换:

查找:

(.{48}){1}
\1\n
替换:

(.{48}){1}
\1\n

说明:

(.{48}){1}
\1\n
  • 括号组成一个组,以便replace可以引用匹配项 使用
    \1
  • 匹配任何字符,
    {n}
    匹配 正是其中的
    n
  • replace命令接受每个匹配组和 back将其替换为附加的换行符
    \n
注意:
\1
技术上仅指找到的第一个匹配项,但使用“全部替换”也会处理剩余的正则表达式匹配项)


真实世界示例:

(.{48}){1}
\1\n
假设您正在格式化公钥,它直接从没有页眉/页脚的浏览器中复制,为Google Internet授权提供以下内容:

9c 2a 04 77 5c d8 50 91 3a 06 a3 82 e0 d8 50 48 bc 89 3f f1 19 70 1a 88 46 7e e0 8f c5 f1 89 ce 21 ee 5a fe 61 0d b7 32 44 89 a0 74 0b 53 4f 55 a4 ce 82 62 95 ee eb 59 5f c6 e1 05 80 12 c4 5e 94 3f bc 5b 48 38 f4 53 f7 24 e6 fb 91 e9 15 c4 cf f4 53 0d f4 4a fc 9f 54 de 7d be a0 6b 6f 87 c0 d0 50 1f 28 30 03 40 da 08 73 51 6c 7f ff 3a 3c a7 37 06 8e bd 4b 11 04 eb 7d 24 de e6 f9 fc 31 71 fb 94 d5 60 f3 2e 4a af 42 d2 cb ea c4 6a 1a b2 cc 53 dd 15 4b 8b 1f c8 19 61 1f cd 9d a8 3e 63 2b 84 35 69 65 84 c8 19 c5 46 22 f8 53 95 be e3 80 4a 10 c6 2a ec ba 97 20 11 c7 39 99 10 04 a0 f0 61 7a 95 25 8c 4e 52 75 e2 b6 ed 08 ca 14 fc ce 22 6a b3 4e cf 46 03 97 97 03 7e c0 b1 de 7b af 45 33 cf ba 3e 71 b7 de f4 25 25 c2 0d 35 89 9d 9d fb 0e 11 79 89 1e 37 c5 af 8e 72 69
搜索并替换(全部)后,您将获得:

9c 2a 04 77 5c d8 50 91 3a 06 a3 82 e0 d8 50 48 
bc 89 3f f1 19 70 1a 88 46 7e e0 8f c5 f1 89 ce 
21 ee 5a fe 61 0d b7 32 44 89 a0 74 0b 53 4f 55 
a4 ce 82 62 95 ee eb 59 5f c6 e1 05 80 12 c4 5e 
94 3f bc 5b 48 38 f4 53 f7 24 e6 fb 91 e9 15 c4 
cf f4 53 0d f4 4a fc 9f 54 de 7d be a0 6b 6f 87 
c0 d0 50 1f 28 30 03 40 da 08 73 51 6c 7f ff 3a 
3c a7 37 06 8e bd 4b 11 04 eb 7d 24 de e6 f9 fc 
31 71 fb 94 d5 60 f3 2e 4a af 42 d2 cb ea c4 6a 
1a b2 cc 53 dd 15 4b 8b 1f c8 19 61 1f cd 9d a8 
3e 63 2b 84 35 69 65 84 c8 19 c5 46 22 f8 53 95 
be e3 80 4a 10 c6 2a ec ba 97 20 11 c7 39 99 10 
04 a0 f0 61 7a 95 25 8c 4e 52 75 e2 b6 ed 08 ca 
14 fc ce 22 6a b3 4e cf 46 03 97 97 03 7e c0 b1 
de 7b af 45 33 cf ba 3e 71 b7 de f4 25 25 c2 0d 
35 89 9d 9d fb 0e 11 79 89 1e 37 c5 af 8e 72 69

你为什么不直接使用/*巨大的注释*/方法?