1

I have a file that unfortunately contains both tabs and spaces.

How do I display them so I know if a particular space is actually tab or space?

3

Several options:

POSIX:

$ printf 'a b\tc \n' | sed -n l
a b\tc $

$ printf 'a b\tc \n' | od -A n -t cx1
   a       b  \t   c      \n
  61  20  62  09  63  20  0a

fairly portable:

$ printf 'a b\tc \n' | cat -vte
a b^Ic $

(some cat implementations have -A as an alias for -vte). Use only -vt or -T with GNU cat if you only care about tab characters and not trailing spaces. Note that the list of characters that cat transforms varies with implementations.

In vi or view, enter :set list for the tabs and end of lines to become visible.

1

Assuming your editor is a fairly modern version of Emacs, then whitespace-mode is what you're looking for. You can customise which questionable whitespace to highlight via the variable whitespace-style:

whitespace-style is a variable defined in whitespace.el. Its value is
(face tabs spaces trailing lines space-before-tab newline indentation empty space-after-tab space-mark tab-mark newline-mark)

Documentation: Specify which kind of blank is visualized.

It's a list containing some or all of the following values:

  • face enable all visualization via faces (see below).

  • trailing trailing blanks are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • tabs TABs are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • spaces SPACEs and HARD SPACEs are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • lines lines which have columns beyond whitespace-line-column are highlighted via faces.
    Whole line is highlighted.
    It has precedence over lines-tail (see below).
    It has effect only if face (see above) is present in whitespace-style.

  • lines-tail lines which have columns beyond whitespace-line-column are highlighted via faces.
    But only the part of line which goes beyond whitespace-line-column column.
    It has effect only if lines (see above) is not present in whitespace-style and if face (see above) is present in whitespace-style.

  • newline NEWLINEs are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • empty empty lines at beginning and/or end of buffer are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • indentation::tab 8 or more SPACEs at beginning of line are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • indentation::space TABs at beginning of line are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • indentation 8 or more SPACEs at beginning of line are visualized, if indent-tabs-mode (which see) is non-nil; otherwise, TABs at beginning of line are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-after-tab::tab 8 or more SPACEs after a TAB are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-after-tab::space TABs are visualized when 8 or more SPACEs occur after a TAB, via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-after-tab 8 or more SPACEs after a TAB are visualized, if indent-tabs-mode (which see) is non-nil; otherwise, the TABs are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-before-tab::tab SPACEs before TAB are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-before-tab::space TABs are visualized when SPACEs occur before TAB, via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-before-tab SPACEs before TAB are visualized, if indent-tabs-mode (which see) is non-nil; otherwise, the TABs are visualized via faces.
    It has effect only if face (see above) is present in whitespace-style.

  • space-mark SPACEs and HARD SPACEs are visualized via display table.

  • tab-mark TABs are visualized via display table.

  • newline-mark NEWLINEs are visualized via display table.

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.