How To Save a File in Vi / Vim Text Editor

To save a file in Vi or Vim text editor, you can follow these steps:

  1. Press the Esc key to enter the command mode in Vi or Vim.
  2. Type “:w” followed by a space and then the filename to save the file under that name. For example, to save the file as “myfile.txt”, you would type:
:w myfile.txt
  1. If the file has already been saved before and you want to overwrite the existing file, you can use the “:w!” command instead. For example:
:w! myfile.txt
  1. If you want to save the file under its existing name, you can use the “:w” command without specifying a filename. For example:
:w
  1. You can also save the file and exit the editor in one command by using the “:wq” command. This will save the file and quit Vi or Vim. For example:
:wq
  1. If you do not want to save the changes you have made and want to exit the editor without saving, you can use the “:q!” command. For example:
:q!

These are the basic commands for saving a file in Vi or Vim text editor. Once you have saved the file, you can use the same filename and path to open the file in the editor again.

Leave a Comment