gpt4 book ai didi

sublimetext2 - 在一定数量的字符后自动中断评论

转载 作者:行者123 更新时间:2023-12-03 15:19:07 25 4
gpt4 key购买 nike

是否可以突出显示大的注释 block 并在一定长度后自动插入中断?

简单示例

# 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它有能力完全满足您的需求。 wrap_linesPackages/Default/paragraph.py 中定义,第 112 行,并且在 the Unofficial Docs' list of commands 中的文档很少。 :

wrap_lines
Wraps lines. By default, it wraps lines at the first ruler’s column.

  • width [Int]: Specifies the column at which lines should be wrapped.

wrap_lines已经可以通过 Edit -> Wrap 中的项目访问菜单。有选项可以将光标位于第 70、78、80、100 和 120 列的段落以及第一个标尺换行。默认情况下, Wrap Paragraph at Ruler映射到 Alt+Q在 Windows 和 Super+Alt+Q 上在 OSX 上。

与统治者合作

我说的第一任统治者是什么意思?您可以通过 View -> Ruler 召唤统治者,但如果您想要在屏幕上显示多个(或者希望您的标尺在书写中),您可以将一个 JSON 整数数组(每个整数定义一个标尺)添加到任何 .sublime-settings文件。例如,我添加到用户首选项文件中的数组如下所示:
"rulers":
[
79,
80,
72
],

多亏了第一个统治者规则, Alt+Q将在 79 列标记处换行超过 79 个字符的行,即使在第 72 列的“之前”有一个标尺。“第一个标尺” 不代表最左边的标尺 ,但 第一个定义的标尺 .如果我搬家 80,像我在下面那样索引 0,然后这些行将在 80 列处换行。 72 也是如此.
"rulers":
[
80,
79,
72
],

使用键绑定(bind)

统治者是为弱者服务的,你说?你也可以写一个新的 key binding在您选择的列处换行!只需将这样的内容添加到您的 Preferences -> Key Bindings – User文件:
{ "keys": ["alt+q"], "command": "wrap_lines", "args": {"width": 80} },

删除 args对象会在第一个标尺处换行,例如 Wrap Paragraph at Ruler命令可以。 Wrap Paragraph at Ruler实际上就像在默认的 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!

但是,如果该行恰好以任何其他符号开头,例如引号的开头,那么 Sublime Text 也不会更好地包装这些符号。所以这:
# "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命令 定位光标所接触的整个段落 ,不仅是当前行,令人惊讶的是,不仅是工作选择。这意味着您可以在新包装的一系列行上再次使用该命令以将它们重新包装在不同的列中,但您最终也可能会包装一些您不想要的行 - 就像您正在对齐Markdown 中标题下的一段:
# 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.

如果该命令在该文本 block 中的任何位置被激活,您将得到:
# 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.

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

关于sublimetext2 - 在一定数量的字符后自动中断评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16990014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com