Explain how to exit Vi and return to shell

Source: Internet
Author: User

After a long period of development, I will share my personal understanding that exit Vi and return to shell to discuss with you. Linux has all the features of a modern, fully functional UNIX system, including real multitasking, virtual memory, shared libraries, excellent memory management, and TCP/IP network support.

Exit Vi and return to shell

You can use one of the following methods to exit Vi and return to shell after editing the file. In command mode, the upper-case letter Z is used for two connections. If the current edited file has been modified, Vi will save the file and exit, and return to shell; if the edited file has not been modified, exit Vi and return to shell.
In the last line mode, enter the command: w Vi to save the current edited file, but does not exit, but continues waiting for the user to enter the command. When you use the w command, you can create a new file name for the editing file.

: W newfile
At this time, Vi will save the content of the current file to the specified newfile, while the original file remains unchanged. If newfile is an existing File, Vi will display the prompt message in the status line of the display window: File exists use! To override) at this time, if you really want to replace the original content in newfile with the current content of the file, you can use the command.
: W! Newfile otherwise, you can select another file name to save the current file. In the last line mode, enter the command
: Q system exits Vi and returns to shell. If the editing file is not saved when you exit Vi with this command, the last line of the Vi display window displays the following information:
No write since last change use! To overrides) indicates that the file is not saved after modification, and then Vi does not exit. Continue waiting for the USER command. If you want to force exit Vi without saving the modified file, you can use the command
: Q! Vi quit the modification and directly exits Vi and returns to shell. In the last line mode, enter the command
: Wq Vi will save the file first, and then exit Vi and return to shell. In the last line mode, enter the command
This command has the same functions as the ZZ command in command mode.

Row number in Vi

Many Commands in Vi use numeric values such as row number and row number. If the edited file is large, it is inconvenient to calculate it by yourself. Therefore, Vi provides the function of adding row numbers to texts. These row numbers are displayed on the left of the screen, and the content of the corresponding row is displayed after the row number.
Run the following command to exit Vi and return to shell: set number in the last line
It should be noted that the row numbers added here are only displayed to users, and they are not part of the file content.
In a large file, you may need to know which row of the cursor is and where it is. You can use the key combination in command mode. In this case, Vi will display the corresponding information in the last line of the display window. This command can be used at any time.

# Include
Main)
{Int k;
For k = 0; k <3; k ++) add );}
Add)
{Static int x = 0;
X ++;
Printf "x = % d \ n", x );
"Example. c" [Modified] lines 4 of 10 -- 40% -- col 11
In the last line mode, we can enter the abbreviation of the nu word number command) to obtain the row number of the current line of the cursor and the content of the row to exit Vi and return to shell.

  1. Linux vi editor concepts
  2. Sunflower collection in linux vi Editor
  3. Describes how to use the basic commands of the linux vi editor.
  4. Linux vi command replacement instructions
  5. Tips for adding a row number to a linux vi command line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.