Скрыть непечатные символы в Vim
Vim показывает непечатаемые символы с префиксом ^
(например ^@
для байта NUL). У меня есть файл на основе столбцов, содержащий как печатные, так и непечатные символы, которые трудно читать, поскольку каждый непечатный символ сдвигает все оставшиеся столбцы на один символ вправо.
Есть ли способ скрыть непечатные символы или просто отобразить вместо них символ-заполнитель? Я также не против, чтобы каждый персонаж был представлен двумя персонажами.
3 ответа
Это контролируется 'isprint'
вариант. С тех пор (цитирую :help
) "Символы от пробела (ASCII 32) до" ~ "(ASCII 126) всегда отображаются напрямую", единственный способ - сжать специальные символы. Вы можете сделать это через
:set isprint=1-255
В зависимости от вашего шрифта эти символы (например, ^[
), вероятно, будет отображаться как пустые ячейки дисплея или как обычный символ замены.
Может быть, вы могли бы использовать conceal
особенность:
:syn match nonprinting /[^[:print:]]/ conceal cchar=%
И установить conceallevel
если вы еще этого не сделали:
:set conceallevel=1
Это все равно будет расширять символы, когда на них наведен курсор:
чтобы лучше понять ответ @muru:
Может быть, вы могли бы использоватьconceal
особенность:
:syn match nonprinting /[^[:print:]]/ conceal cchar=%
:set conceallevel=1
Другой пример
:syn match name_you_like /[^[:print:]]/ conceal cchar=!
:set conceallevel=2
после этой следующей строки,set concealcursor?
получаетconcealcursor=
:set concealcursor='nvic'
И я не знаю почему.
обновление: мы можем сделать
:set concealcursor=nvic
или
:set concealcursor=nc
Просто поиграйтесь с этими тремя настройками.
объяснение:
Подробности из документа
1.syn match
Возможно, мы можем игнорировать те элементы синтаксиса, которых нет выше...
DEFINING MATCHES *:syn-match*
:sy[ntax] match {group-name} [{options}]
[excludenl]
[keepend]
{pattern}
[{options}]
{group-name} A syntax group name such as "Comment".
[{options}] See |:syn-arguments| below.
[excludenl] Don't make a pattern with the end-of-line "$"
extend a containing match or region. Must be
given before the pattern. |:syn-excludenl|
keepend Don't allow contained matches to go past a
match with the end pattern. See
|:syn-keepend|.
{pattern} The search pattern that defines the match.
2. :син-шаблон
Syntax patterns :syn-pattern E401 E402
In the syntax commands, a pattern must be surrounded by two identical
characters. This is like it works for the ":s" command. The most common to
use is the double quote. But if the pattern contains a double quote, you can
use another character that is not used in the pattern. Examples:
:syntax region Comment start="/\*" end="\*/"
:syntax region String start=+"+ end=+"+ skip=+\\"+
See pattern for the explanation of what a pattern is. Syntax patterns are
always interpreted like the 'magic' option is set, no matter what the actual
value of 'magic' is.
And the patterns are interpreted like the 'l' flag is not included in 'cpoptions'.
This was done to make syntax files portable and independent of the 'magic' setting.
Try to avoid patterns that can match an empty string, such as "[a-z]*".
This slows down the highlighting a lot, because it matches everywhere.
[:alnum:] [:alnum:] isalnum ASCII letters and digits
[:alpha:] [:alpha:] isalpha ASCII letters
[:blank:] [:blank:] space and tab
[:cntrl:] [:cntrl:] iscntrl ASCII control characters
[:digit:] [:digit:] decimal digits '0' to '9'
[:graph:] [:graph:] isgraph ASCII printable characters excluding
space
[:lower:] [:lower:] (1) lowercase letters (all letters when
'ignorecase' is used)
[:print:] [:print:] (2) printable characters including space
[:punct:] [:punct:] ispunct ASCII punctuation characters
[:space:] [:space:] whitespace characters: space, tab, CR,
NL, vertical tab, form feed
[:upper:] [:upper:] (3) uppercase letters (all letters when
'ignorecase' is used)
[:xdigit:] [:xdigit:] hexadecimal digits: 0-9, a-f, A-F
[:return:] [:return:] the <CR> character
[:tab:] [:tab:] the <Tab> character
[:escape:] [:escape:] the <Esc> character
[:backspace:] [:backspace:] the <BS> character
[:ident:] [:ident:] identifier character (same as "\i")
[:keyword:] [:keyword:] keyword character (same as "\k")
[:fname:] [:fname:] file name character (same as "\f")
The square brackets in character class expressions are additional to
the square brackets delimiting a collection.
For example, the following is a plausible pattern for a UNIX filename:
[-./[:alnum:]_~]\+`
That is, a list of at least one character, each of which is
either '-', '.', '/', alphabetic, numeric, '_' or '~'.
3. скрыть
conceal conceal :syn-conceal
When the "conceal" argument is given, the item is marked as concealable.
Whether or not it is actually concealed depends on the value of the
'conceallevel' option.
4. cchar
cchar :syn-cchar
E844
The "cchar" argument defines the character shown in place of the item
when it is concealed If "cchar" is not set then the default conceal
character defined in the 'listchars' option is used. The character cannot be
a control character such as Tab.
See hl-Conceal for highlighting.
5. уровень скрытия
'conceallevel' 'cole'
'conceallevel' 'cole' number (default 0)
local to window
Determine how text with the "conceal" syntax attribute :syn-conceal
is shown:
Value Effect
0 Text is shown normally
1 Each block of concealed text is replaced with one
character. If the syntax item does not have a custom
replacement character defined (see :syn-cchar) the
character defined in 'listchars' is used.
It is highlighted with the "Conceal" highlight group.
2 Concealed text is completely hidden unless it has a
custom replacement character defined (see
:syn-cchar).
3 Concealed text is completely hidden.
Note: in the cursor line concealed text is not hidden, so that you can
edit and copy the text. This can be changed with the 'concealcursor'
option.
6. скрыть курсор
'concealcursor' 'cocu'
'concealcursor' 'cocu' string (default: "")
local to window
Sets the modes in which text in the cursor line can also be concealed
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
'v' applies to all lines in the Visual area, not only the cursor.
A useful value is "nc". This is used in help files. So long as you
are moving around text is concealed, but when starting to insert text
or selecting a Visual area the concealed text is displayed, so that
you can see what you are doing.
Keep in mind that the cursor position is not always where it's
displayed. E.g., when moving vertically it may change column.