1. if 语句:
let number = 10
if number > 5
echo "Number is greater than 5"
elseif number == 5
echo "Number is equal to 5"
else
echo "Number is less than 5"
endif
2. ternary 运算符:
let result = (number > 5) ? "Greater than 5" : "Less than or equal to 5"
echo result
3. switch 语句:
let fruit = "apple"
switch fruit
\ case "apple"
\ echo "It's an apple"
\ case "orange"
\ echo "It's an orange"
\ case "banana"
\ echo "It's a banana"
\ else
\ echo "It's something else"
endswitch
4. && 和 || 运算符:
let x = 5
let y = 10
if x > 0 && y > 0
echo "Both x and y are greater than 0"
endif
if x == 5 || y == 5
echo "Either x or y is equal to 5"
endif
这些是一些基本的 Vimscript 条件语句和运算符的用法。在实际使用中,根据需要选择适当的条件语句来执行代码块。此外,你还可以使用 :help if, :help switch, :help expr1 ? expr2 : expr3 等命令来查看 Vim 文档以获取更详细的信息。
转载请注明出处:http://www.zyzy.cn/article/detail/10373/vim编辑器