Vimscript是否允许使用多行字符串?
python和ruby命令允许使用以下格式::python << EOF
你能用字符串做类似的事吗?
答案 0 :(得分:50)
Vimscript确实允许继续前一行,用反斜杠开始下一行,但这不像你在Ruby,PHP或Bash中找到的heredoc字符串那么方便。
let g:myLongString='A string
\ that has a lot of lines
\ each beginning with a
\ backslash to continue the previous one
\ and whitespace before the backslash
\ is ignored'
答案 1 :(得分:5)
枚举工作分配并包括上一个工作分配,可以使您在各行之间保持一致
let foo = "bar"
let foo = foo . 123
echom foo "prints: bar123
使用复合字符串串联运算符点等于:
let foo = "bar"
let foo .= 123
echom foo "prints: bar123
列出您的字符串和数字并加入它们:
let foo = ["I'm", 'bat', 'man', 11 ][0:4]
echo join(foo) "prints: I'm bat man 11
与上述相同,但要加入数组切片
let foo = ["I'm", 'bat', 'man', [ "i'm", "a", "mario" ] ]
echo join(foo[0:2]) . " " . join(foo[3])
"prints: I'm bat man i'm a mario
行首的反斜杠允许行继续
let foo = "I don't think mazer
\ intends for us to find
\ a diplomatic solution"
echom foo
let foo = 'Keep falling,
\ let the "grav hammer" and environment
\ do the work'
echom foo
打印:
I don't think mazer intends for us to find a diplomatic solution
Keep falling, let the "grav hammer" and environment do the work
巧妙地将您的秘密文本和最古老的文字隐藏在功能内:
function! myblockcomment()
(*& So we back in the club
// Get that bodies rocking
!#@ from side to side, side side to side.
!@#$ = %^&&*()+
endfunction
自由格式文本的存储位置是它在磁盘上的位置。该函数永远不会运行,否则解释器会呕吐,因此一直存在,直到您使用vim反射获取myblockcomment()
的实现,然后执行您想要的任何事情。请勿这样做,除了会引起眼花and乱和困惑。
答案 2 :(得分:0)
您不能使用<<
创建字符串,但是可以使用<<
创建字符串列表。
参见:help :let=<<
以下是vim doc中的示例
let text =<< trim END
if ok
echo 'done'
endif
END