0

example:

function! MkStatusLine()
  let &stl=''
  let &stl.='%{abcd()}'
endfunction

function abcd()
 if this 
    return ' myvalue'
 elseif this
    return ' '
 endif
endfunction

How can I return a space?
return ' ' is seen as return ''
return ' myvalue' is seen as return 'myvalue'

Reman
  • 7,931
  • 11
  • 55
  • 97

1 Answers1

1

I suspect you are misinterpreting your results and that your function is working correctly. Check what

:echo '#'.abcd().'#'

produces. You should observe # # and not ##.

If not, are you sure there is only two paths in your function?

What about the else path? You can debug it with: :debug echo abcd(). From there you can go to next instruction, or step-in a function call, or finish the call to the current function, you can continue till next breakpoint, etc. See :h :debug.

What is sure is that spaces can be returned in VimL. If the first line of your function is a return ' ', you'll see that a space is returned.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • Hi Luc, tnx for replying. You're right. It works fine but it doesn't work in statusline. I updated my question. – Reman Dec 16 '15 at 08:30
  • OK. You only want a single space in that case? May I ask why a space instead of nothing? If it was about padding, there are other ways. – Luc Hermitte Dec 16 '15 at 08:34
  • yes it was about padding. In my example in above question I only have one function in the statusline. In reality I have more functions. If there is a value to return, I want to create a padding of 1 space before the value to return. If not no padding. – Reman Dec 16 '15 at 09:27