Sublime Forum

Create A New Text Doc From Selections

#1

Hi,

In my work flow, I need to highlight portions of a text on at a time ( say from source.txt) and add them to a new document ( say to, sink.txt). I was wondering if there is a plugin for doing this. If not, any guidance on how to do his would be greatly appreciated.

CS

0 Likes

#2

Yes there is, but I can’t find it. I’ll look a bit more.

Got it! Here it is: https://packagecontrol.io/packages/Edit%20in%20new%20tab

Is that what you were looking for @chikitin

0 Likes

#3

Hi math2001,

If I do my selections first and then click "edit in new tab’. Otherwise, it opens one tab for each selection. I need a plugin that append the selection into a single tab ( or document). No matter how many times I select from the source document.

I am pretty sure the plugin can be modified so that it dumps the selections into a single tab. Thank you.

import sublime, sublime_plugin

class EditInNewTabCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        selection_text = ""
        # open a new file
        view = sublime.active_window().new_file()

        # get selected text
        sels = self.view.sel()
        for sel in sels:
           selection_text = selection_text + self.view.substr(sel) + '\n'

        # insert selected text into the new file
        view.insert(edit, 0, selection_text[:-1])

So I need “Edit in new Tab” to create a new tab only once ( only for the first time), and if I do Edit in new tab, it stays in the source tab not showing the opened tab. I hope this is possible. I guess the created file should be global ( or static on the disk) for above plugin to work.

Thank you very much,
CS

0 Likes