【问题标题】:Paste multi-cursor copy/paste WITHOUT newlines in sublime text在崇高的文本中粘贴多光标复制/粘贴而不带换行符
【发布时间】:2016-06-17 11:31:36
【问题描述】:

有没有办法粘贴多光标(Ctrl+dCtrl+d、...Ctrl+C)选择,去掉换行符?

如果[...]代表高亮,代表光标:

The ⦙[red].
The ⦙[blue].
The ⦙[green].

如果我粘贴,我会得到:

red
blue
green⦙

但我想要

redbluegreen⦙

这可能吗?

【问题讨论】:

标签: sublimetext2 sublimetext3 sublimetext sublime-text-plugin


【解决方案1】:

保存以下脚本@:
/Packages/Paste Without NewLines/paste_without_newlines.py

 

import sublime, sublime_plugin

class paste_without_newlines( sublime_plugin.TextCommand ):
    def run( self, edit ):

        clipboard = sublime.get_clipboard()
        clipboard = clipboard.replace( "\n", "" )
        sublime.set_clipboard( clipboard )
        self.view.run_command( "paste" )

 


 

要通过Command Palette > Paste Without NewLines执行,添加以下代码@:
/Packages/Paste Without NewLines/Default.sublime-commands

 

[
    {
        "caption": "Paste Without NewLines",
        "command": "paste_without_newlines",
    },
]

 


 

要通过Ctrl + Shift + Alt + V执行,添加以下代码@:
/Packages/Paste Without NewLines/Default.sublime-keymap

 

[
    {
        "keys": ["ctrl+shift+alt+v"],
        "command": "paste_without_newlines",
    },
]

【讨论】:

  • 不需要插件.replace( "\r", "" ) 中的第二个替换。 Sublime Text 总是只使用\n 在内部表示新行,而不管操作系统和当前文件的行尾设置如何。行结束设置仅在保存文件时生效。见:Is a newline always represented internally by ‘\n’?
  • 还有一个sublime_plugin.TextCommand 类名(以及一个ApplicationCommand,但不是一个EventListener)应该使用CamelCase 后跟单词Command。在这种情况下,PasteWithoutNewlinesCommand 应该在 class paste_without_newlines... 行中使用而不是 paste_without_newlines。 ST 将 CamelCaseCommand 类名翻译成 ST snake_name 命令,即paste_without_newlines,去掉Command 结尾。公平地说,插件按原样工作,但plugins documentation 对此很清楚。
  • 以防万一我不清楚 PasteWithoutNewlinesCommand 插件类名称被转换为 ST paste_without_newlines 命令,所以这仍然应该在键绑定和命令调色板条目中使用.
  • @mattst :很好的电话\r,我不想查找并添加它以防万一。 a sublime_plugin class name should use CamelCase followed by the word Command我不同意。您链接到 非官方 文档,并且已知 官方 文档不完整。我曾经使用PluginNameCommand,直到我找到一些使用plugin_name 的例子。海事组织;这是一个更好的选择,因为它反映了将在命令中使用的实际文本,并且不需要 Command 后缀的冗余。此外,由于 ST 对它们的处理方式相同,因此使用它没有任何问题。
  • 如您所愿,但在非官方文档herehere 的多个地方给出了相同的建议,并且非官方文档链接自main ST support pageDefault.sublime-package 存档中的所有插件都对继承 TextCommandApplicationCommandWindowCommand 但不是 EventListener 派生类的类使用 CamelCaseCommand 约定,所以也许是有原因的。
【解决方案2】:

对于遇到此问题的其他人来说,有一个 sublime text 包可以解决这个确切的问题,它被称为 Paste PDF Text Block

然后,您可以 Ctrl+Alt+v 将要从 pdf 文件复制到 Sublime Text 中的新文件中的文本。

工作很愉快,如果你对用崇高的文本制作自己的包不够了解,这是一个很好的解决方案,比如我:(

【讨论】:

    猜你喜欢
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多