2013-10-22 200 views

回答

1

這可能不是你超越它,只是你在編程語言之前沒有遇到過!。這很簡單,但這是一個快速解釋。

如果您想根據某個條件做某件事,那麼您使用if語句,對吧?例如,

if has('relativenumber') 
    echo "Your Vim has the relative number feature!" 
endif 

如果你想要做的事,如果這一條件是真的,你的條件之前把!。 (這被稱爲「否定」邏輯條件)

if !has('relativenumber') 
    echo "Your Vim does NOT have the relative number feature." 
endif 

你也可以在其他情況下使用它。拿這個,例如:

if x > 3 
    echo "x is greater than three" 
endif 

你必須包括圓括號否定它。 (操作順序!)

if !(x > 3) 
    echo "x is less than or equal to three" 
endif 

這相當於

if x <= 3 
    echo "x is less than or equal to three" 
endif 
+0

好吧,現在它是有道理的。也許我正在自己領先一點。我無法磨合一種我不得不否定價值的情況。請記住,我剛剛在2個月前拿起了Vim。 –

+0

這不像一個編程事物那麼簡單。你可能會在某個時候需要,現在你會知道該怎麼做。我不會爲此擔心。 – pandubear

+0

有點無關:我正在使用Vim7.4,並且使用has('relativenumber')並不適合我。什麼*做*工作:如果存在('&relativenumber')。 –

相關問題