Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 343
Artur Kim Avatar asked Oct 07 '22 04:10

Artur Kim


1 Answers

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" }
like image 85
Riccardo Marotti Avatar answered Oct 10 '22 01:10

Riccardo Marotti