[英]Vim statusline: show the character itself
Is there a way to show the character under the cursor in the statusline? 有没有办法在状态行中显示光标下的字符?
I already use %b\\ (0x%B)
to display decimal and hexadecimal value of the character. 我已经使用%b\\ (0x%B)
来显示字符的十进制和十六进制值。 I would like to display the char itself as well before these two. 我想在这两个之前显示char本身。
There's no predefined item (as listed under :help 'statusline'
, but you can implement this with a custom expression (item %{...}
): 没有预定义项目(如下所示:help 'statusline'
,但您可以使用自定义表达式(项目%{...}
)实现此项:
let &statusline .= "%{matchstr(getline('.'), '\\%' . col('.') . 'c.')}"
(I'm using :let
instead of :set
to avoid having to escape all spaces; it's more readable this way.) (我正在使用:let
而不是:set
以避免必须逃避所有空格;这种方式更具可读性。)
getline('.')
obtains the current line, and the character under the cursor is retrieved via the special \\%c
atom that matches at a certain column; getline('.')
获取当前行,并通过在某列匹配的特殊\\%c
原子检索游标下的字符; col('.')
is the current column. col('.')
是当前列。 The .
的.
then matches the character there, and matchstr()
extracts it. 然后匹配那里的字符, matchstr()
提取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.