Qual é a melhor maneira de exibir tabulações / espaços em meus arquivos de texto simples

1

Eu tenho um arquivo que infelizmente contém guias e espaços.

Como os exibo para saber se um determinado espaço é realmente uma guia ou um espaço?

    
por CodeNoob 19.10.2015 / 18:15

2 respostas

3

Várias opções:

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

razoavelmente portátil:

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

(algumas implementações de cat têm -A como um alias para -vte ). Use apenas -vt ou -T com GNU cat se você se importar apenas com os caracteres de tabulação e não com espaços à direita. Observe que a lista de caracteres que cat transforma varia com as implementações.

Em vi ou view , insira :set list para que as guias e o final das linhas se tornem visíveis.

    
por 19.10.2015 / 18:31
1

Supondo que seu editor seja uma versão bastante moderna do Emacs, então whitespace-mode é o que você está procurando. Você pode personalizar o espaço em branco que pode ser questionado para destacar por meio da variável 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.

    
por 19.10.2015 / 19:25