The Vim (Vi Improved) text editor may have originally been written decades ago, but its powerful set of keystrokes and philosophy of "modal editing" still make it a favorite among Linux users and programmers. Nonetheless, it lacks many of the conventional user interface features of more recent editors, such as a main menu, so users are forced to learn keystrokes for all tasks.
Press "Escape." This will take you out of "Insert" mode and into "Command" (or "Normal") mode.
Type ":wq." The colon indicates that what follows is a Vim command, the "w" indicates that the file should be written, or saved, and the "q" indicates that Vim should quit, or exit.
Add the filename at the end of the command if you are saving a new document. So, instead of ":wq", you should type ":wq filename.txt."