Sublime Forum

How to copy/paste multiple lines?

#1

Hello there, I’m not sure how to explain this, so I believe this video would be self-explanatory.

I have two sets of text. I need to copy and paste them both in order to merge their contents. However, it isn’t enough by simply merging them. I need to duplicate the contents of one of the sets into the other set.

Into this:

I already tried this:

But as you can see, it doens’t work…

Any advise?

0 Likes

#2

it does work as you suggest. The issue you are facing is that there is a mismatch in your cursors and text buffers.

For example if you copy text from 4 text selections you have 4 text buffer in your clipboard. You’ll then need 4 text cursors to paste from all buffer.

What happens in your case is that the numbers of buffer / cursors mismatch so you paste all buffers on every cursor.

0 Likes

#3

Yup, I found that out a few minutes after I published and trying to troubleshoot :smile:

Any advise? Any addon for that? or any alternative?

Kind regards.

0 Likes

#4

When you need to such specific task, the easiest approach is writing your own script, it is really not that complex, and worth the effort to learn since you will then be able to automate a lot of things within sublime.

I made a quick one to get you started:

import sublime, sublime_plugin

class PasteNplicateCommand(sublime_plugin.TextCommand):

	def run(self, edit):
		clipboard = sublime.get_clipboard().replace('\r\n', '\n').replace('\r', '\n').split('\n')
		print(clipboard)
		for i,sel in enumerate(self.view.sel()) :
			r = self.view.line(sel)
			line = self.view.substr(r)
			ls = line.split(',')
			nl = ''
			for x in ls :
				if nl:
					nl += ','
				nl += clipboard[i] + x
			self.view.replace(edit, r, nl)

Save that in your user package directory (Preferences->Browse package to find the directory)

Copy your word lines, and then do a multiple select on the number lines (you just need one cursor by line, no matter where the cursor actually is) and call the plugin.
To call the plugin, just add the following keybinding:

{ "keys": ["f5"], "command": "paste_nplicate" },
0 Likes

#5

He/she is probably not a Python Maven.

0 Likes

#6

Script doesn’t work, maybe it’s outdated by now.

0 Likes