2011-02-06 14 views
5

私は、多くの場合、フォームの変数への代入を見てきました「のを聞かせて= 『何か』を。」ここで私が理解するのに苦労してきたのvimスクリプト内のコードの特定の部分だ: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,'$'))をタブ名に追加すると、「1:2/4バッファ名」のように見えます。その外観から、.=の操作はsに追加されているようです。しかし、最初の2つの行が何をするのか分かりません。どんな助けもありがとうございます。一度

+2

'='文字列連結ショートカット演算子です。基本的に 's = sです。何か ' –

答えて

7

Vimのonlinehelpはあなたの友達です:

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

一つ:iは= 9、S = "bleah" 仮定


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

、sは今や "bleahの%の9T"


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

であろう。これは、より馴染みの三項演算子でありますC.もしt == 9であれば、sは今や "漂白%9T%1 *"である。 tは何もしかし 9されている場合は、S今ある "bleah%の9T%は2 *"

関連する問題