Vim 显示以 a 为前缀的不可打印字符^
(例如^@
NUL 字节)。我有一个基于列的文件,其中包含可打印和不可打印字符,该文件很难阅读,因为每个不可打印字符都会将其余所有列向右移动一个字符。
有没有办法隐藏不可打印的字符或仅显示占位符?我也不介意每个字符都用两个字符表示。
答案1
这是由'isprint'
选项控制的。由于(引用自:help
)“从空格(ASCII 32)到‘~’(ASCII 126)的字符总是直接显示”,唯一的方法是压缩特殊字符。您可以通过以下方式做到这一点
:set isprint=1-255
根据您的字体,这些字符(如^[
)可能会显示为空的显示单元或通用替换字符。
答案2
答案3
为了更好地理解@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
只需尝试一下这 3 个设置即可。
解释:
各部分 | 描述 |
---|---|
syn match |
定义一个match |
nonprinting |
a group-name ,你喜欢什么就做什么? |
/[^[:print:]]/ |
Apattern |
|
|
conceal |
将您指定的物品标记为可隐藏 |
cchar=% |
隐藏字符,这里是% |
详细信息来自文档
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. :syn-模式
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
'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.