12

I'm a little puzzled about some default values in Vim. In particular, for gq{motion}, is said that

[...]
If the 'textwidth' option is 0, the formatted line
length is the screen width (with a maximum width of
79).

I thought that it should have made more sense if it would have set the max width to 80, instead.

Can someone enlighten me about this? I guess I'm missing something.

  • 1
    Well, 80 is a pretty arbitrary "standard" to begin with so… why not 79? Now, wrapping lines at 79 in a 80 columns-wide terminal gives a bit more room to the right and may improve legibility. github.com/vim/vim/blob/… – romainl Aug 8 '16 at 17:52
  • 2
    Maybe, on 80 columns-wide terminal the last column was reserved for the wrapping symbol? Still, if you have line numbers on, then they will definitely take more than just one column. So, I'm still puzzled. Moreover, from the code you linked, is 79 the max value it can be used? Maybe I did not understand what I read. – Atcold Aug 8 '16 at 19:58
  • 3
    ... or you can just set textwidth and be done with. – VanLaser Aug 8 '16 at 21:18
  • 13
    80 is the number of columns of old hardware terminals, and later of MS DOS (text mode) screens. tw=79 instead of tw=80 because displaying a line 80 characters long on an 80 columns terminal prints an extra newline. – Sato Katsura Aug 9 '16 at 8:52
  • 7
    A newline is always added. If it happens to be the 81st character on an 80 characters wide terminal you just get a full line followed by an empty one. – Sato Katsura Aug 9 '16 at 13:45
7

I don't have any evidence that this is why 79 was originally chosen, but one good reason to leave it at that value is because if you use 'list' with a value included for eol in 'listchars' then the display of the listchar will cause an 80-character-length line to wrap onto the next line in an 80-character-wide terminal.

If the line is only 79-characters long, then the 80th column is free for the end-of-line listchar to sit in.

  • I didn't get it. Where am I supposed to use 'list'? What is it supposed to do? – Atcold Nov 10 '17 at 16:30
  • @Atcold It's an option that causes characters that are usually invisible (such as the end of line) to be displayed on screen. See :help 'list' or just try running :set list to see it in action. – Rich Nov 10 '17 at 16:59
  • :set list does not do much. I bet I don't have the eol in the listchars. I'm not very sure this is the reason behind the 79 characters. I believe @sato-katsura has the best answer in the comment. – Atcold Nov 10 '17 at 17:11
  • eol is in 'listchars' by default, but of course it's possible something in your config has removed it. I specifically state in my answer that I have no reason to believe that this was the historical reason that 79 was originally chosen. I'm just giving another reason why it continues to be a good value to use, now. – Rich Nov 10 '17 at 17:39
  • @Atcold. Newline is not displayed by default, it does not make sense to reserve an extra character for that. – Christian Brabandt Nov 11 '17 at 11:41
6
+50

It is important to realize that this "default" only applies to the gq and gw commands and auto-format as described in that section. The default textwidth is 0. Furthermore, :right and :center default to 80, not 79.

As for why 79 was chosen, it cannot be a direct hold-over from vi since gq, gw, and auto-format do not exist in vi. This is mostly speculation, but I believe the 79 default for auto-format was chosen for consistency with vi's existing auto-wrapping. That this applies for gq and gw is a side-effect; one might expect 80 would have been chosen otherwise.

In vi (and in vim if textwidth=0) text starts auto-wrapping at the window width minus wrapmargin. However, if wrapmargin=0, no auto-wrapping will take place. This means that if you were using an ADM-3A with an 80 character limit, with wrapmargin=1, the maximum width with auto-wrapping is 79. An upside to this behavior is that there is a place for the cursor to live while waiting to see what the next character is going to be before deciding where to wrap. Of course, vi and vim could put the cursor on the next line (as observed when typing a very long word) but leaving an extra column is a bit nicer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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