Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question may have been asked before but I was unable to find any solution.

When I browse and see some code that I would like to copy, I simply use Ctrl+C and Ctrl+V. Most of the time this works fine, but in some cases (websites like StackOverflow and a few others), when I copy the code and paste it, it only comes on one line in Eclipse. I have tried pasting this code into Eclipse, then selecting all and then Auto Format but this doesn’t help either. I have also pasted the code into Komodo and Word with the same results. The code simply refuses to align itself.

Does anyone know any solution to this?

share|improve this question
    
Does it copy all the code and 'consolidate' it on one line? If that is the case you might have a problem with line breaks. –  Hennes Jun 30 '12 at 13:58
    
Thats exactly what it does. Line break problem in word,komodo and eclipse - If so how would i change it? –  Sab Jun 30 '12 at 14:29
add comment

1 Answer

I am not really comfatable posting this as an answer since I did not test it and I rarely encounter the problem myself. However one the few occasions that I ran into these problems I could work around it by pasting into an editor which understands multiple forms of line ending. Usually I use vim for this, but I think both wordpad and notepad++ also work. This works as an occasional workaround. It is not what I consider a 'proper' solution


A bit of background to explain why this will work:

In the days of mechanical typewriters you typed all text on a single line. When you reached the end of that line you usually wanted to do two things:

  1. Return the cariage head to the beginning of the line
  2. Scroll the paper one line so the next text starts below it.

These are refered to as CR and LF. (Cariage Return and Line Feed).

Computers needed something similar. Most unix based systems used the linefeed. However windows decided to use both CR LF to mark the end of a line. To confuse things further Macintosh just used CR.

share|improve this answer
    
I used wordpad and it didnt work. Just for you to test, you can copy any code(must be in code brackets) on stack overflow(java preferably since xml seems to work okay in auto format in eclipse) and paste it into wordpad. It is completely disorganized. –  Sab Jun 30 '12 at 15:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.