If an astronomical object were no longer within the gravitational field of any other object, it would still retain its own inertia and continue to move in a straight line at a constant velocity. This principle is known as Newton's first law of motion, or the law of inertia.
In the absence of external forces acting upon it, an object will maintain its state of motion. This means that if an object is initially at rest, it will remain motionless. Conversely, if the object has an initial velocity, it will continue to move in a straight line with a constant speed.
In the vastness of space, objects can be influenced by gravitational forces from nearby celestial bodies. However, if an object were far removed from the gravitational influence of other objects, its motion would be determined solely by its initial velocity and would persist indefinitely unless acted upon by external forces, such as a collision or the gravitational pull of another object.
It is worth noting that in reality, completely isolating an object from all gravitational influences is practically impossible since gravitational fields extend infinitely, albeit with decreasing strength as distance increases.