I am trying to use the join command to join multiple strings. The join command seems to add one character of space in between each of the strings. But I don't want any space added.

As an example, I'm working on a function that finds the associated .pdf file of a .tex file. So if I'm editing the file /home/user/paper.tex, I would like to create the string /home/user/paper.pdf. My attempt is

join([expand('%:p:r'), '.pdf'])

which returns /home/user/paper .pdf


From :help join():

join({list} [, {sep}])


            When {sep} is specified it is put in between the items.  If
            {sep} is omitted a single space is used.


So the solution is to add an empty string in the second sep parameter:

:echo join([expand('%:p:r'), '.pdf'])
/usr/share/vim/vim81/doc/eval .pdf

:echo join([expand('%:p:r'), '.pdf'], '')

In this case you don't really need to use join() by the way, and could just use:

:echo expand('%:p:r') . '.pdf'
  • Thanks. So in your last command, you have a period between the strings. I've seen a period used like that before, but I don't understand, what does it do? – wxyz Sep 12 '18 at 7:49
  • 2
    See :help expression-syntax . In this context '.' is string concatenation. – wbogacz Sep 12 '18 at 9:26
  • I want to make note that I didn't realize that :help join and :help join() bring you to different parts of the help section. – wxyz Oct 2 '18 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.