Two-dimensional (2D) vanadium disulfide (${\mathrm{VS}}_{2}$) can serve as a universal host for reversible intercalation and deintercalation of alkali and alkaline earth metal ions. However, its practical application in rechargeable metal-ion batteries is limited by its low energy density (559 Wh ${\mathrm{g}}^{\ensuremath{-}1}$). Herein, the effects of $\mathrm{O}$ doping and $\mathrm{C},\mathrm{O}$ codoping on the electrochemical performance of 2D ${\mathrm{VS}}_{2}$ used as anode for magnesium-ion batteries (MIBs) are investigated by first-principles calculations. Values of both the energy density and specific capacity increase with increasing $\mathrm{O}$-doping concentration, and those of $\mathrm{VSO}$ are 2.17 times and 1.16 times higher than those of ${\mathrm{VS}}_{2}$, respectively. However, due to the strong bond between $\mathrm{O}$ and $\mathrm{Mg}$, the diffusion barrier of $\mathrm{Mg}$ atoms on 2D $\mathrm{VSO}$ is relatively high (1.02 eV). Further introduction of $\mathrm{C}$ (${\mathrm{VSO}}_{0.75}{\mathrm{C}}_{0.25}$) can reduce the diffusion barrier of $\mathrm{Mg}$ atoms (0.80 eV) to a level comparable to that of ${\mathrm{VS}}_{2}$. Meanwhile, the values of energy density and specific capacity of ${\mathrm{VSO}}_{0.75}{\mathrm{C}}_{0.25}$ are 1.53 times and 1.17 times those of ${\mathrm{VS}}_{2}$. Our results suggest that $\mathrm{O}$ doping and $\mathrm{C},\mathrm{O}$ codoping of 2D ${\mathrm{VS}}_{2}$ are effective strategies to improve the overall performance of MIBs and it should be possible to generalize such doping strategies to other rechargeable MIBs based on 2D transition metal dichalcogenides.