Vim 9 cheatsheet

Vim 9: Saving and quitting

7 common Vim 9 tasks.

Save the file

Write the buffer to disk and stay in Vim.

:w

Save and quit

Write the file and exit Vim.

:wq

Quit

Exit Vim. It refuses if there are unsaved changes.

:q

Quit without saving

Exit and throw away all unsaved changes.

:q!

Caution: Unsaved changes are lost.

Save and quit from normal mode

Write only if changed and exit, without typing a command.

ZZ

Save all files and quit

Write every modified buffer and exit.

:wqa

Save a file you opened without sudo

Write a root-owned file through sudo and tee after forgetting to open it with sudo.

:w !sudo tee % > /dev/null

Was this page helpful?