Mic*_*ski 54
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'
Run Code Online (Sandbox Code Playgroud)
枚举分配并包括前一个分配可让您连接线
let foo = "bar"
let foo = foo . 123
echom foo "prints: bar123
Run Code Online (Sandbox Code Playgroud)
使用复合字符串连接运算符dot equals:
let foo = "bar"
let foo .= 123
echom foo "prints: bar123
Run Code Online (Sandbox Code Playgroud)
列出您的字符串和数字并加入它们:
let foo = ["I'm", 'bat', 'man', 11 ][0:4]
echo join(foo) "prints: I'm bat man 11
Run Code Online (Sandbox Code Playgroud)
与上面相同,但加入数组切片
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
Run Code Online (Sandbox Code Playgroud)
行开头的反斜杠允许行继续
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
Run Code Online (Sandbox Code Playgroud)
打印:
I don't think mazer intends for us to find a diplomatic solution
Keep falling, let the "grav hammer" and environment do the work
Run Code Online (Sandbox Code Playgroud)
在一个函数中隐藏你的秘密文本和大多数古代文本:
function! myblockcomment()
(*& So we back in the club
// Get that bodies rocking
!#@ from side to side, side side to side.
!@#$ = %^&&*()+
endfunction
Run Code Online (Sandbox Code Playgroud)
自由格式文本的内存位置是它位于磁盘上的文件.该函数永远不会运行,或者解释器会呕吐,所以直到你使用vim反射来实现myblockcomment()然后做你想做的任何事情.除了睡觉和混淆之外,不要这样做.
您不能用于<<创建字符串,但可以用于<<创建字符串列表。看:help :let=<<
下面是 vim 文档中的示例
let text =<< trim END
if ok
echo 'done'
endif
END
Run Code Online (Sandbox Code Playgroud)