IntelliJ: String paste auto quote escaping

Answered

IntelliJ has this strange feature (bug for me) wherein if I paste text with quote marks in it inside an existing String, then my quote marks get auto-escaped.

Thus, I can end up with strange code like this:

System.out.println(" lottery distribution: \" median = \" + median + \", madm = \" + madm + \", k = \" + k + \", delta = \" + delta  );

when what I want is this:

System.out.println(" lottery distribution: median = " + median + ", madm = " + madm + ", k = " + k + ", delta = " + delta  );

I am using IntelliJ 8.1.3.  I have searched under the Editor settings, and cannot find where to suppress this behavior.  I would be very grateful if you could tell me how to suppress it.

This bug was noted 6 years ago (altho the bug vote link in the second posting there no longer works).


p.s. this forum's web interface seems to have changed.  How are you supposed to format code examples?  I see icons for links, images, etc, but the usual forum code icon seems to be missing.  I had to hand format the font of the code snippets above, which is unacceptable in a forum devoted to programming...

5 comments
Comment actions Permalink

Hello Charlie,

There is a separate action for pasting without auto-escaping: Paste Simple.
You can remap the keyboard shortcuts to trigger Paste Simple by Ctrl-V.

IntelliJ has this strange feature (bug for me) wherein if I paste text
with quote marks in it inside an existing String, then my quote marks
get auto-escaped.

Thus, I can end up with strange code like this:

System.out.println(" lottery distribution: \" median = \" + median +
\", madm = \" + madm + \", k = \" + k + \", delta = \" + delta  );

when what I want is this:

System.out.println(" lottery distribution: median = " + median + ",
madm = " + madm + ", k = " + k + ", delta = " + delta  );

I am using IntelliJ 8.1.3.  I have searched under the Editor settings,
and cannot find where to suppress this behavior.  I would be very
grateful if you could tell me how to suppress it.

/message/3353182#3353182 (altho the bug vote link in the second
posting there no longer works).

p.s. this forum's web interface seems to have changed.  How are you
supposed to format code examples?  I see icons for links, images, etc,
but the usual forum code icon seems to be missing.  I had to hand
format the font of the code snippets above, which is unacceptable in a
forum devoted to programming...

---
Original message URL:
http://www.jetbrains.net/devnet/message/5260219#5260219

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


1
Comment actions Permalink

Dmitry: thanks for your prompt reply.

I am embarassed to admit that I was not aware of the Paste Simple option.

I think that I am going to skip the keyboard remapping, because I do want the "complicated" Paste for things like autoimport etc when I do non-String pastes.  But when I want to paste a String inside a String, I will try and remember to do a Paste Simple instead.  That should do the trick.

0
Comment actions Permalink

My IntelliJ does not auto-escape, and I am direly in need of finding the toggle for this…

0
Comment actions Permalink

Which action do you use for pasting? What is the file type? Could you please share a short video of the issue?

0
Comment actions Permalink

I use the normal Ctrl-V, but also tried the various Paste▶ commands, and it’s a Java class.

Heh, apparently this is dependent of the position in the file… it doesn’t do this outside of a method.

0

Please sign in to leave a comment.