Tlgrok/Form Feeds and Vertical Tabs

"Form feed" and "vertical tab" are two control characters found in the ASCII character coding scheme, with the the character codes 12 and 11 respectively. They are both meant to format a printed output: "form feed" represents a page break, and "vertical tab" is an instruction for the printer to move a certain number of rows down. These characters are both ignored by most modern terminals. Vim display "form feed" as ^L, and "vertical tab" as ^K. In Vim's insert mode, to insert a form feed press Ctrl-l; to insert a vertical tab, press Ctrl-k Ctrl-k Ctrl-k (that's Ctrl-k three times - you might want to use a mapping).

Important note: Throughout the rest of this tip, ^L shall be used to represent a form feed, and ^K a vertical tab. These are not the characters '^' and 'L' or 'K'; these are Vim's representation of the form feed and vertical tab control characters.``

Despite not longer being used in formatting printing output, these control characters still have their uses. Probably the most important thing about them is that, in many programming languages, such as C and C++, they are considered whitespace. Thus, the following is a perfectly valid C statement:

Vim treats form feeds in the first column as section delimiters (see :help section. If you're writing a plain-text treatise, for instance, you may use form feeds to delineate chapters. You may jump to start of the current or previous section by typing [[ in Normal mode, and to the start of the next section using ]].

As said above, C and C++ compilers treat form feeds as whitespace, so they may easily be used, uncommented, to group together related functions. The following appears in the GNU Coding Standards:

Please use formfeed characters (control-L) to divide the program into pages at logical places (but not within a function). It does not matter just how long the pages are, since they do not have to fit on a printed page. The formfeeds should appear alone on lines by themselves. [1]

While Vim doesn't have any special method to handle vertical tabs, they can be made useful using some scripting. Particularly, vertical tabs can be used as placeholders in template- or abbreviation-generated text. For instance, say you've got an abbreviation which produces the following:

for (;;) {};

There are obviously places in the above where additional text should be filled in. We can use a vertical tab as a placeholder, producing code which looks like the following:

for (^K;^K;^K) {^K};

(If you're using a color terminal, Vim will color the '^K's differently than the rest of the text, making them easier to spot.)

The neat thing is that, vertical tabs being whitespace, the above is perfectly valid C code, and, if we did not yet replace it, a placeholder can remain in place when a file is compiled.

To easily jump to the next placeholder, I use the following, which you can add to your .vimrc:

In Normal mode, '[h' and ']h' jump to the previous or next placeholder.

In Insert mode, Shift-<Left> and Shift-<Right> do the same thing. The global variable g:replace_placeholder determines whether the target placeholder should be automatically removed whenever a jump takes place. (The variable is declared global in case you want to put the above code in a plugin.)

Using these bindings, it is easy to jump to location where text needs to be filled in.