Search code examples
pycharmcopy-paste

How do I paste multiple selected lines one to one in PyCharm?


I have two files, and I want to paste the lines from file A in to the multi-selections of file B.

File A contains the lines:

foo0
foo1
foo2
foo3

And file B with the lines:

var0 = "foo0"
somevar = False
var1 = "foo0"
some_other_var = False
var2 = "foo0"
some_code_I_have_to_work_around = False
var3 = "foo0"

I want to paste the lines from file A in to the values of the variables in file B so that it looks like this:

var0 = "foo0"
somevar = False
var1 = "foo1"
some_other_var = False
var2 = "foo2"
some_code_I_have_to_work_around = False
var3 = "foo3"

But I keep getting output that looks like:

var0="foo0
foo1
foo2
foo3"
somevar = False
var1="foo0
foo1
foo2
... <snip>

How do I tell PyCharm I just want it to paste exactly the number of lines from file A in to the values of file B without pasting ALL the lines from my copy in to each of my multi-selections?


Solution

  • The answer is to use multi-selection in both the source copy, and destination paste.

    Select multiple non-contiguous ranges

    I use the Sublime Text hotkey mapping, so my key for "select next occurrence of thing" is + D. The default PyCharm is Ctrl + G, according to the documentation.

    I was trying to paste a single selection into a multi-selection, hence PyCharm was pasting my single selection in to the multi-selection like I asked it to.

    I had thought that PyCharm would behave like Sublime Text and automatically recognized that the exact number of lines in my single selection matched the number of lines in my multi-selection, and intelligently placed them.