Suppose I am defining a few commands that are similar in functionality. In this particular case, I am defining a few commands that each echoes a particular message:
function! EchoMessage(text) echom textendfunctionlet thousand_chars = "天地玄黃,宇宙洪荒。日月盈昃,辰宿列張。寒來暑往,秋收冬藏。閏餘成歲,律呂調陽 ..."let lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, ..."let brown_fox = "The quick brown fox jumps over the lazy dog."command! ThousandCharacters call EchoMessage(thousand_chars)command! LoremIpsum call EchoMessage(lorem_ipsum)command! BrownFox call EchoMessage(brown_fox)
I have written it in this way to be able to reuse EchoMessage
for many commands. Unfortunately, an error is produced when any of the commands (e.g. :LoremIpsum
) are called, because vim will not provide text
when EchoMessage
is called using a command.
How can I structure my code so that the commands can make use of a common function (e.g. EchoMessage
) with one argument provided in the script itself (e.g. brown_fox
)?