def str_to_vim(obj):
    """Encode Python object `obj` as vim string.

    Parameters
    ----------
    obj : :obj:
        Object to be encoded.

    Returns
    -------
    str
        Double-quoted string.
    """
    # pylint: disable=undefined-variable  # unicode
    # Encode
    if not isinstance(obj, bytes):
        obj = obj.encode()
    obj = str(obj, 'utf-8')

    # Vim cannot deal with zero bytes:
    obj = obj.replace('\0', '\\0')

    # Escape
    obj.replace('\\', '\\\\').replace('"', r'\"')

    # Return double-quoted string
    return f'"{obj:s}"'