Save and Exit in Vi Editor in Linux

Need to press [Esc] key followed by the colon (:) before typing the following commands:

Commands  Description
q Quit
q! Quit without saving changes i.e. discard changes.
r [file_name] Read data from file called [file_name]
wq Write and quit (save and exit).
w Write to file called [file_name] (save as).
w! Overwrite to file called [file_name] (save as forcefully).
!cmd Runs shell commands and returns to Command mode.

vi Editor in Linux

The default editor that comes with the Linux/UNIX operating system is called vi (visual editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just read a text file. The advanced version of the vi editor is the vim editor. 

Table of Content

  • How to Open VI Editor
  • Modes of Operation in the vi editor
  • Linux vi Commands and Examples
  • Moving within a File (Navigation) in Vi Editor  
  • Control Command (Scrolling) in vi Editor
  • Inserting and Replacing text in Vi Editor
  • Deleting Characters and Lines in Vi Editor
  • Copy and Paste in Vi editor in Linux
  • Save and Exit in Vi Editor in Linux
  • Searching and replacing in (ex-Mode) in Vi Editor (Linux)
  • Block delete commands in (x mode) in Vi Editor  
  • Block copy command in (x mode) in Vi Editor  
  • Block moving commands in (x mode) in Vi Editor  

Similar Reads

How to Open VI Editor

To open vi editors, we just need to type the command mentioned below....

Modes of Operation in the vi editor

There are three modes of operation in vi:...

Linux vi Commands and Examples

NOTE: vi editor in Linux is a case-sensitive....

Moving within a File (Navigation) in Vi Editor :

To move around within a file without affecting text must be in command mode (press Esc twice). Here are some of the commands that can be used to move around one character at a time....

Control Command (Scrolling) in vi Editor :

There are the following useful commands which can be used along with the Control Key. These commands are helpful in saving time by navigating quickly in a file without manually scrolling....

Inserting and Replacing text in Vi Editor :

To edit the file, we need to be in the insert mode. There are many ways to enter insert mode from the command mode....

Deleting Characters and Lines in Vi Editor :

Here is the list of important commands which can be used to delete characters and lines in an opened file....

Copy and Paste in Vi editor in Linux:

Copy lines or words from one place and paste them in another place by using the following commands....

Save and Exit in Vi Editor in Linux:

Need to press [Esc] key followed by the colon (:) before typing the following commands:...

Searching and replacing in (ex-Mode) in Vi Editor (Linux):

vi also has powerful search and replacement capabilities. The formal syntax for searching is:...

Block delete commands in (x mode) in Vi Editor :

need to press ESC and then commands will be followed by colon (:)....

Block copy command in (x mode) in Vi Editor :

need to press ESC and then commands will be followed by colon (:)....

Block moving commands in (x mode) in Vi Editor :

need to press ESC and then commands will be followed by colon (:)....

Basic vi Command and Working – FAQs

What is the difference between vi and vim editor?...

Conclusion

Vi editor is a powerful and widely used text editor in UNIX and Linux operating system. It allows us to create, edit and manage text files. Vim is the advanced version of vi editor. There are three modes in vi: Command mode, Last Line Mode and Insert Mode. We have also discussed many options in the above context. Overall, we can say that it is a powerful tool and it is useful for both beginners and experienced users....