Linux vi save exit command (how to exit vi)

  

There are many ways:

Exit Vi When editing the file, ready to exit Vi and return to the shell, you can use one of the following methods. In the command mode, double-click the uppercase letter Z. If the currently edited file has been modified, Vi saves the file and exits, returning to the shell; if the currently edited file has not been modified, Vi exits directly. Return to the shell. In the last line mode, enter the command :w Vi to save the current edit file, but not exit, but continue to wait for the user to enter the command. When using the w command, you can give the edit file a new file name. [Example 6] :w newfile At this point, Vi will save the contents of the current file to the specified newfile, while the original file remains unchanged. If newfile is an existing file, Vi gives a prompt message in the status line of the display window: File exists (use ! to override) At this point, if the user really wants to replace the original content in the newfile with the current content of the file, Use the command :w! newfile otherwise you can choose another file name to save the current file. In the last line mode, enter the command :q The system exits Vi and returns to the shell. If the edit file is not saved when you exit Vi with this command, Vi displays the following information at the last line of the display window: No write since last change (use ! to overrides) prompts the user that the file has not been saved after being modified, and then Vi does not quit and continues to wait for user commands. If the user wants to save the modified file and wants to quit Vi, you can use the command :q! Vi to abandon the changes and return directly to the shell. In the last line mode, enter the command :wq Vi to save the file first, then exit Vi and return to the shell. In the last line mode, enter the command :x The function of this command is the same as the ZZ command function in command mode.

Copyright © Windows knowledge All Rights Reserved