Reman
Reman

Reputation: 8109

How to return a space from function in vim?

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'

Upvotes: 0

Views: 110

Answers (1)

Luc Hermitte
Luc Hermitte

Reputation: 32926

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.

Upvotes: 1

Related Questions