".=" 在 vim 脚本中代表什么意思?

8

我经常看到这样的变量赋值形式:"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)和视图窗口编号(tabpagewinnr(i,'$')winnr)添加到选项卡名称中,使其看起来像“1: 2/4 Buffer name”。从外观上看,.= 操作似乎是将内容附加到s上。但是,我不明白前两行代码是做什么的。感谢任何帮助。

2
".="是字符串连接的快捷操作符。它基本上等同于s = s . somethingelse。" - Marc B
2个回答

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

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*"。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接