Does Vimscript allow multi-line strings?
You can not use <<
to create string, but you can use <<
to create list of string.
see :help :let=<<
below is example from vim doc
let text =<< trim END
if ok
echo 'done'
endif
END
Vimscript multi-line strings, dot operator:
Enumerating assignments and including the previous lets you concat over lines
let foo = "bar"
let foo = foo . 123
echom foo "prints: bar123
Use a compound string concatenation operator dot equals:
let foo = "bar"
let foo .= 123
echom foo "prints: bar123
Make a list of your strings and numbers and join them:
let foo = ["I'm", 'bat', 'man', 11 ][0:4]
echo join(foo) "prints: I'm bat man 11
Same as above but join with array slicing
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
A backslash at the beginning of line allows for line continuation
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
Prints:
I don't think mazer intends for us to find a diplomatic solution
Keep falling, let the "grav hammer" and environment do the work
Hide your secret text and most ancient tomes inside a function thustly:
function! myblockcomment()
(*& So we back in the club
// Get that bodies rocking
!#@ from side to side, side side to side.
!@#$ = %^&&*()+
endfunction
The memory location of the free form text is the file where it sits on disk. The function is never run, or the interpreter would puke, so there it until you use vim reflection to get the implementation of myblockcomment()
then do whatever you want. Don't do this except to bedazzle and confuse.
Vimscript does allow continuation of the previous line by starting the next with a backslash, but that isn't quite as convenient as a heredoc string such as you would find in Ruby, PHP, or Bash.
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'
Have a look at the relevant documentation on line-continuation.