How to add space between value and unit in Conky

It seems a bit heavy going, but if your conky was compiled with lua then you can write a small piece of code to split the output string and add a space. Create a file, say ~/myformat.lua with contents:

function conky_myformat(arg)
 local val = conky_parse(arg)
 return string.gsub(val, "([%d.-]+)(%a+)", "%1 %2", 1)
end

and add to your .configrc in the conky.config part:

lua_load = '~/myformat.lua',

and replace each function like ${mem} by a call to the above function, for example

conky.text = [[
 old: ${mem} and ${memmax}
 new: ${lua myformat ${mem}} and ${lua myformat ${memmax}}
]]

lua does not use regular expressions (regex), but patterns which are similar, see the documentation. %d matches a digit, %a a letter, and () is used to capture the match for use in the replacement string as %1 and so on.

Alternatively, you could compile your own conky from source, changing the function human_readable() in src/conky.cc.


Version 1.11.6 added a space between values and units, in about August 2020. I'm not sure if this was an intentional change, it was part of a fix for SI units. It should be in 20.10, but not 20.04.

The latest source includes a configuration setting for what to use as a spacer between values and units, including nothing, but this is not yet released so you'd need to build it yourself.