2

We know \f was used in C as form feed in earlier times. Still the escape sequence is for form feed. How does it behave in (modern) terminals now? It looks same as vertical space \v (rather than new line \n which we naturally expect).

  • Is \f the same as \v now when printed on screens?
  • Why is \f printing a vertical space on screens now? Instead of start of next page, isn't start of next line more natural?
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Cyriac Antony
  • 386
  • 1
  • 3
  • 13
  • Since `\f` is a form feed, you'd expect it to clear the screen and set the writing position to the top-left of the screen (unless, perhaps, you're working with a terminal in Arabic, or …). If you don't set vertical tab stops (how would you do that?), it's reasonable that a vertical tab behaves like a form feed. I have used `\f` in times long past; I don't think I've ever used `\v`, though. – Jonathan Leffler Feb 27 '18 at 05:44
  • 7
    **What are you really trying to do?** – selbie Feb 27 '18 at 05:46
  • https://stackoverflow.com/questions/4334370/escape-sequence-f-form-feed-what-exactly-is-it – Support Ukraine Feb 27 '18 at 06:06
  • 1
    @4386427: The other question is helpful w.r.t `\f`; unfortunately, it makes no mention of `\v` at all. The expected behaviour of `\f` is fairly straight-forward; I've never known what `\v` was intended to do and regard it as useless. Clearly, someone, somewhere, had a use for it — but I'd regard `\e` for 'escape' (ESC, `\033` or `\x1B` or `\u001B`) as more useful than `\v`, though I believe one reason that it wasn't standardized is that there is no equivalent to 'escape' in EBCDIC. – Jonathan Leffler Feb 27 '18 at 06:18
  • @JonathanLeffler True - therefore I didn't mark it as a dup. I gave the link just in case OP could find some relevant info there. – Support Ukraine Feb 27 '18 at 06:22
  • @4386427: Yes — I've tweaked my comment marginally. I'd regard it as more plausible that `\v` behaves like `\f` than vice versa — if such a difference can be considered valid. And, referring to the question, there's no way that I'd expect a form feed to equate simply to a newline; I'd regard a terminal that does that as broken. However, that means that the Mac Terminal is broken — fortunately, I don't use form-feeds now (and haven't in this millennium). And empirically, at the shell prompt, `printf "ab\fcd"` and `printf "ab\vcd"` produce the same output — a newline without carriage return. – Jonathan Leffler Feb 27 '18 at 06:28
  • I see this in [What is a vertical tab?](https://stackoverflow.com/q/3380538/995714) "A vertical tab was the opposite of a line feed i.e. it went upwards by one line. It had nothing to do with tab positions. If you want to prove this, try it on an RS232 terminal" Not sure about the correctness – phuclv Feb 27 '18 at 07:27
  • EBCDIC does have an ESC code, just not at \x1B, that is still defined similarly to ESC in ASCII-68. This is not how ISO-646 currently makes use of the code, however, so the two aren't compatible. – M. Ziegast Feb 27 '18 at 09:40

3 Answers3

3

How control characters render on a terminal depends on the terminal emulator, not the programming language you use. So you should search for documentation about your particular system.

For example, a Linux console responds to \v and \f in the same way:

LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a linefeed, and if LF/NL (new-line mode) is set also a carriage return;

(quoted from man 4 console_codes)

Note that despite the above statement, the character 0x0A (\n) will echo as a CR-LF sequence because of the underlying terminal default onlcr setting, which causes newlines to be automatically translated to a CR-NL sequence. See man stty.

rici
  • 234,347
  • 28
  • 237
  • 341
3

When line printers tended to use the green and white striped 11" x 14" fan fold paper, the equipment usually set VT to advance to the next lower inch, as HT would advance to the next multiple of 8 column, so applications could get output aligned to the top of one of those stripes without the extra code of counting lines per page to add individual LF codes manually, or possibly wasting a lot of paper if only FF was available. This was generalized in ISO6429 with the VTS code and other sequences. Using a code like this let the equipment speed up the paper advance over line at a time also, as it knew the paper didn't have to be stationary to print a possible graphic in the lines skipped.

M. Ziegast
  • 165
  • 4
  • Nice ISO6429 ref. Per [ECMA-48](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf), looks like VT went to the next vertical tab stop and the default tab stops were 1 line apart. – chux - Reinstate Monica Feb 27 '18 at 12:33
  • There is no default, actually... It's device dependent and might even be 0 if there is no 'next tab stop'. For most video terminals that scroll off the top without buffering, or the old teletypes, 1 is what got used most often. – M. Ziegast Feb 27 '18 at 20:14
  • Some printers in the 60's used a punched carriage control tape loop, which made `/v` `/f` programmable. "IBM 1443 flying typebar printer. Basic rate of 150 lines a minute and up to 430 lines a minute, depending on typebar Interchangeable typebars having character sets of 13, 39, 52, and 63 characters. The tape specifies form length and the form line where printing was to begin so that paper of various sizes could be used." http://bitsavers.trailing-edge.com/pdf/ibm/1620/A26-5730-2_1443_printer_for_1620.pdf – ShpielMeister Sep 11 '21 at 22:37
2

C handles them transparently (usually with the ASCII code on nearly all not very ancient compilers).

Terminals handles the ASCII control code. As in the answer of @rici, on consoles usually they are equivalent, but terminals are a wide concept. \v is used for printers (especially on old printers where one sent directly characters to printers [also now it is so, but sending Postscript code (also in ASCII), and never the old plain text + formatting sequences]), e.g. headers and footers. Also \f makes a lot more sense on printer: new page.

The \v and \f are very seldom used. According The C Book (Annotated Reference), Table 866.2, \v is used 0.31% of all escape sequences, and \f 0.44%.

BTW \f (^L) is more often found on C code (as ASCII character) then as escape character in C code. Some editors put it to split regions (e.g. for hiding/showing just some regions). But also this (in my experience) is fading out: editors are now smarter, so they could automatically select regions (functions, declarations, etc. levels, including also with any sort of documentation convention [in comments] just before declaration/definitions]).

Note: some escape sequences are also used on communication between programs, to define "end of record (but not of communication).

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32