繁体   English   中英

vim脚本中的“。=”是什么意思?

[英]What does “.=” in vim scripts mean?

我经常看到对“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 )和视winnrtabpagewinnr(i,'$')tabpagewinnr(i,'$') )添加到选项卡名称,使其看起来像“1:2/4缓冲区名称”。 从它的外观来看, .=操作似乎是在向s添加内容。 但是,我不明白前两行是做什么的。 任何帮助表示赞赏。

vim的在线 帮助是你的朋友:

: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". 

一次一个:


let s .= '%' . i . 'T'

假设i = 9且s =“bleah”,s现在将是“bleah%9T”


let s .= (i == t ? '%1*' : '%2*')

这是来自C的熟悉的三元运算符。如果t == 9,那么s现在是“bleah%9T%1 *”。 如果t是什么,但 9,则S现在是“bleah%9T%2 *”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM