110

I am in the process of writing a text editor. After looking at other text editors I have noticed that a number of them refer to a "soft" versus "hard" wrap. What is the difference? I can't seem to find the answer by searching.

titaniumdecoy
  • 17,909
  • 17
  • 93
  • 130

3 Answers3

149

A hard wrap inserts actual line breaks in the text at wrap points, with soft wrapping the actual text is still on the same line but looks like it's divided into several lines.

Firas Assaad
  • 22,872
  • 16
  • 57
  • 75
21

It's usual for text editors to auto-wrap text into paragraphs with hard newlines, but it's less common for the text to be re-flowed into a nice paragraph if you come back later and edit/add/remove words later on. (You can do this manually in emacs with M-q.)

This is rather annoying, since obsessive compulsive people like me then go back and have to manually re-insert the hard breaks at the appropriate points.

On the other hand, soft wrapping is annoying because most all command line tools use line-based diff-ing (version control is where this becomes most noticeable to me). If you've got a 1/3-page paragraph that's soft wrapped and fix a typo, it's basically impossible to see where the change is in a regular diff output or similar.

Will Robertson
  • 55,636
  • 31
  • 91
  • 113
  • 2
    I know you said 'regular' diff, however I would like to point out that highlighting is a godsend. – SW. Sep 08 '11 at 21:12
  • 1
    @Will, So what kind of solution do ocd folks like you reccommend? – Pacerier Jul 15 '15 at 01:45
  • If you use Vim, with line numbers turned on (:set nu) then you will find that it soft wraps lines, but keeps them separate, so if an individual line is wider than the screen you will still be able to read all the text, but it won't mess up your ability to search by line numbers. (A visible line is different to an actual line). You can also jump straight to a line by typing :10 or :30, etc. – daviewales Apr 25 '16 at 08:49
  • If you're using Git, it's easy to see changes with soft wrapping. Use `git diff --word-diff` – Anthony Ebert Sep 18 '19 at 14:29
17

soft : The text in the textarea is not wrapped when submitted in a form. This is default

hard : The text in the textarea is wrapped (contains newlines) when submitted in a form. When "hard" is used, the cols attribute must be specified

Reference: W3Schools

RevanthKrishnaKumar V.
  • 1,779
  • 1
  • 19
  • 33