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

时间:2011-02-06 05:00:23

标签: vim

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

2 个答案:

答案 0 :(得分:7)

vim的online help是你的朋友:

: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
 non-zero, 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 :(得分:0)

一次一个:


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 *”