Accepted answer

okay, i just found the answer (on stackoverflow, no less).

eclipse has an option so that copy-paste of multi-line text into string literals will result in quoted newlines:

preferences/java/editor/typing/ "escape text when pasting into a string literal"


as far as i know this seems out of scope of an ide. copyin ,you can copy the string and then try to format it using ctrl+shift+ f most often these multiline strings are not used hard coded,rather they shall be used from property or xml files.which can be edited at later point of time without the need for code change


the eclipsepasteasjavastring plug-in allows you to insert text as a java string by ctrl + shift + v


paste as usual via ctrl+v:

some text with tabs and new lines

paste as java string via ctrl+shift+v

"some text\twith tabs\r\n" + "and new \r\n" + "lines"


see: multiple-line-syntax

it also support variables in multiline string, for example:

string name="zzg";
string lines = ""/**~!{
    select * 
        from user
        where name="$name"


select * 
    from user
    where name="zzg"


if your building that sql in a tool like toad or other sql oriented ide they often have copy markup to the clipboard. for example, toad has a ctrl+m which takes the sql in your editor and does exactly what you have in your code above. it also covers the reverse... when your grabbing a formatted string out of your java and want to execute it in toad. pasting the sql back into toad and perform a ctrl+p to remove the multi-line quotes.


you can use this eclipse plugin: this is a multi-line string editor popup. place your caret in a string literal press ctrl-shift-alt-m and paste your text.

Related Query

More Query from same tag