python - 崇高文本 3 API : Get all text from a file

标签 python select text sublimetext3 sublime-text-plugin


我正在尝试为 sublime text 3 创建一个插件。
现在我只能选择一个窗口中的所有文本并将其复制到另一个窗口中。
代码:

import sublime, sublime_plugin

class PrintCodeCommand(sublime_plugin.WindowCommand):
    def run(self):
        # for each caracter, add it to a string with the substr method
        s = ""
        for x in range(0,self.window.active_view().size()):
            s += self.window.active_view().substr(x)
        newFile = self.window.new_file()
        newFile.run_command("test",{"textBuffer": s})

class Test(sublime_plugin.TextCommand):
    def run(self, edit, textBuffer):
        self.view.insert(edit, 0, textBuffer)

你知道更好/更简单的方法吗?
谢谢!

最佳答案

您可以通过以下方式获取当前文档的内容:

contents = self.view.substr(sublime.Region(0, self.view.size()))

关于python - 崇高文本 3 API : Get all text from a file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182008/

相关文章:

python - 在 wxPython 中使用触摸板手势?

html - 如何在 html 下拉列表中显示类别名称?

python - 是否有更 pythonic 的方式来组合列表中的重复对象?

python - 如何保存临时图像,然后使用opencv显示它

python - 用python计算csv文件中的列

javascript - 更改时如何将键作为 v-for 的选择选项值传递(VueJS)

SQL View 。选择计数...在哪里

css - 如果您将鼠标悬停在任一 div 上,则使两个相邻的 div 一起滚动

java - 我应该如何解析命令行样式输入?

wpf - 文本框 - 水平文本居中