To save a file in Vi or Vim text editor, you can follow these steps:
- Press the Esc key to enter the command mode in Vi or Vim.
- 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
- 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
- If you want to save the file under its existing name, you can use the “:w” command without specifying a filename. For example:
:w
- 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
- 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.