The vi command to exit and save edits is ZZ. You can also use the ex command :wq to exit and save the edits. Unlike vi commands, the ex commands, introduced by a ':', require a <Return> after the command. To exit vi without saving your changes, use the ex command :q!.