How to copy and paste multiple lines/selections to the same number of multiple lines/selections without mapping them 1:1 in Sublime Text 2?

StackOverflow https://stackoverflow.com/questions/13078134

Question

Every so often, I copy multiple lines of code and then paste them into multiple selections expecting each selection to have that block of code, but instead the block of code gets split into the multiple selections because the number of lines/selections matched. That's the default behavior if the number of lines/selections match, which is useful but not in cases like this one.

My first instinct was to see if there was a shortcut to cancel that behavior as I'm pasting just like how "paste_and_indent"'s shortcut is "super+shift+v". I didn't find one though.

Every time I have this issue, I deselect one of the selections and paste, then select only the one I had deselected and paste.

If anyone knows of a better way of doing this, please share.

Was it helpful?

Solution

I think that the only one shot way is to create a plugin (Tools/New Plugin...) that copies the clipboard into all selected regions:

import sublime, sublime_plugin

class FullMultilinePasteCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            self.view.insert(edit, region.begin(), sublime.get_clipboard())

Save it in your Packages/User directory.

Then you can add the key binding (Preferences/Key Bindings - User):

{ "keys": ["alt+super+v"], "command": "full_multiline_paste" }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top