gpt4 book ai didi

vim - vim 脚本中的 ".="是什么意思?

转载 作者:行者123 更新时间:2023-12-04 10:57:37 26 4
gpt4 key购买 nike

我经常看到对“let s.='something'”形式的变量的赋值这是我一直在努力理解的vim脚本中的特定代码:

let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let s .= i . ':'
let s .= winnr . '/' . tabpagewinnr(i,'$')
let s .= ' %*'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')

该代码将选项卡编号( i )和视口(viewport)编号( winnrtabpagewinnr(i,'$') )添加到选项卡名称中,使其看起来像“1:2/4 缓冲区名称”。从外观上看, .=操作似乎正在向 s 添加内容.但是,我不明白前两行是做什么的。任何帮助表示赞赏。

最佳答案

vim的online help是你的 friend :

:h .=

 :let {var} .= {expr1}    Like ":let {var} = {var} . {expr1}".


:h expr-.

 expr6 .   expr6 ..   String concatenation


:h expr1 (嗯 - 这有点难找):

 expr2 ? expr1 : expr1

The expression before the '?' is evaluated to a number. If it evaluates to TRUE, the result is the value of the expression between the '?' and ':', otherwise the result is the value of the expression after the ':'.
Example:
:echo lnum == 1 ? "top" : lnum

Since the first expression is an "expr2", it cannot contain another ?:. The
other two expressions can, thus allow for recursive use of ?:.
Example:
:echo lnum == 1 ? "top" : lnum == 1000 ? "last" : lnum

To keep this readable, using |line-continuation| is suggested:
:echo lnum == 1
:\ ? "top"
:\ : lnum == 1000
:\ ? "last"
:\ : lnum

You should always put a space before the ':', otherwise it can be mistaken for
use in a variable such as "a:1".

关于vim - vim 脚本中的 ".="是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4911692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com