A common operation when converting files, or just cleaning up files, is to remove trailing spaces. (Trailing spaces are “extra” spaces past the ends of lines.) Trailing spaces can come from several sources:

  • Users often inadvertently add extra spaces to the ends of lines while editing.
  • Some programs, e.g. word processors, add an extra space to each line within a paragraph.
  • The function EDIT > > Convert > All lines same length adds trailing spaces to make all lines the same length.
  • Files exported from databases often have trailing spaces, perhaps corresponding to unused fields.

While trailing spaces generally don't cause problems, sometimes they do, especially if some lines have many trailing spaces. For example, a line with many trailing spaces may print as two lines, with a blank second line. This can be very confusing.

There are several ways to see if a file has trailing spaces.

Find Trailing Spaces
Go to the beginning of the file and select USER > Find trailing spaces . It moves the cursor to the first trailing spaces (or tab characters), if any.
Highlight Cursor Line
Set CONFIG > Display options > Highlight cursor line to “2”. This setting highlights only actual characters on the current line, including trailing spaces. Any trailing spaces on the current line will therefore stand out.
Window Erase
Set CONFIG > Editing colors > Window erase to a non-zero valuewhich is different from “Edited text”. This gives an unusual (and a bitstrange) effect in which the actual text characters are in one color and and the space past the end of each line is in a different color. Its only purpose is to make trailing spaces stand out.
Show Newlines (CR/LF)
Enable VIEW > Options > Show newlines (CR/LF). This lets you see where each line ends; it helps show any trailing spaces.

Assuming you have the default USER menu loaded, it is easy to remove trailing spaces.

Remove Trailing Spaces from the Current File

To remove all trailing "whitespace" (space and tabs) from the entire file click User then Remove trailing spaces. The spaces will be removed and the cursor position will be restored.

The status line briefly indicates how many lines had trailing whitespace removed.

Related Resources