How to save a file in vi and exit

You’ll need to understand about the three modes of vi.

First <escape> will ensure you are in the default mode.

Then use “a” to append or “i” to enter edit mode. From here you can type your comment or change just like in a normal editor.

Then press the <escape> key to break out of it.

Now use the colon “:” key to enter the command mode.

Then: wq

which means write the file and quit.

This will exit the vi editor. If we only wanted to save but not exit we could do “:w” with no q.

Related pages