“什么是”呢=&引用;在vim脚本中是什么意思?
我经常看到以“let s.='something'”形式分配给变量的操作,下面是我一直在努力理解的vim脚本中的特定代码:“什么是”呢=&引用;在vim脚本中是什么意思?,vim,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#' : '%#Tab
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
)和视口编号(tabpagewinner(i,“$”
)的winnr
)添加到选项卡名称中,使其看起来类似于“1:2/4缓冲区名称”。从外观上看,=
操作似乎在向s
添加内容。但是,我不明白前两行是做什么的。感谢您的帮助。一次一个:
let s .= '%' . i . 'T'
假设i=9和s=“bleah”,s现在将是“bleah%9T”
这是C中熟悉的三元运算符。如果t==9,则s现在是“bleah%9T%1*”。如果t不是9,那么s现在是“bleah%9T%2*”维姆是你的朋友:
(嗯,这有点难找到):
=
是字符串连接快捷运算符。基本上是s=s。somethingelse
let s .= (i == t ? '%1*' : '%2*')
:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}".
expr6 . expr6 .. String concatenation
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".