+4 votes
392 views
How to exit VIM Linux

in Linux / Unix by (552k points)
reopened by | 392 views

2 Answers

+4 votes
Best answer

If you don't know what VI or VIM is , it is a text editor that is present in many GNU / Linux distributions and other operating systems . This text editor is widely used for editing text files on servers and is also the weapon of many programmers around the world to write brilliant code in many programming languages.

VI / VIM is very simple, that makes it difficult when you use it for the first time and you have no idea that many of the editor commands are executed by text starting with “:” (colon).

To exit VIM, just place it :qin the VIM normal mode (pressing ESC will achieve the normal mode), this way you can exit without problem. In normal mode you can also combine commands such as :wqsave (w) and close the program (q). VIM runs the commands from left to right, this is important.

Many people do not know that the first time (as I do) and turn to "Saint Google" to learn how to exit VIM without restarting the computer. 

Stackoverflow did very well, a million developers (many from Mexico and Spain) learned how to escape from VI's clutches.

country_stuck_vim-1-2-1024x1024.png

In the previous graph, we see the% of traffic that the “How to exit VIM” post received. It is interesting beyond sounding funny, because almost all of us this happens when we start using VIM.

Do you have an anecdote using VIM? You can comment at the end of the post.


by (552k points)
+5 votes

1. Exit the Vim editor without applying changes to Linux
2. Save files with the Vim editor in Linux
3. Open different Vim modes in Linux

The work of directories in Linux can become a really complex task if we do not have the knowledge or adequate tools. Surely none of us would like to feel cornered when we work with Linux systems, so TechnoWikis is always thinking of offering the best solutions so that the work with files in these systems is as complete as possible. One of the basic utilities to carry it out is the use of a text editor and in this case we speak of the text editor integrated in Linux which is called VIM.

What is Vim?
The Vim editor ("VI IMproved") is literally a VI clone, which is in turn a program similar to the VI text editor used for a long time in UNIX environments and that offers certain practical functions for all types of users.

One of the great advantages of using the Linux vim editor is that it can not only work in text mode but it also includes a graphical interface which adds menus and mouse support with which the benefits will be much greater.

Vim Compatibility
If we talk about compatibility and use, something that is essential, the Vim editor is available for operating systems such as:
  • AmigaOS
  • Atari MiNT
  • BeOS
  • TWO
  • macOS
  • NextStep
  • OS / 2
  • OSF
  • RiscOS
  • SGI
  • UNIX
  • VMS
  • Windows
  • FreeBSD
  • Linux
VIM features
When we decide to use the vim editor in Linux we will have some features like:
  • Execution of automatic commands.
  • Support of multiple characters and languages.
  • Compatible with the group of characters iso-latin1 and for the termcap.
  • Completion commands.
  • Macro recording functions.
  • Detection and conversion of file formats.
  • Windows divided vertically.
  • Syntax highlighting
  • Highlighted parentheses, brackets, keys and more signs.
  • Vimdiff function thanks to which we can edit two or three files and Vim will show the differences between these and many more.

We can see how the use of the vim editor is really complete and functional, the problem is that many users, novices or not, are lost during the use of the editor and do not detect the way to exit safely and we will explain various methods for this process.

Note
In case of not having vim in the used distro we can install it executing:
 sudo apt install vim 

image

To stay up to date, remember to subscribe to our YouTube channel! SUBSCRIBE


1. Exit the Vim editor without applying changes to Linux


When we access vim but do not make any changes or it was not the idea to access it, we must understand that the vim editor is executed in normal mode which is no longer an indication that the file is not being modified.
Step 1

To exit without making any changes we must enter the following. Press Enter and in this way we will exit the vim editor in Linux.
 : q 

image

Step 2

Now, if when we execute this the error "Without writing since the last change" is displayed, it means that we have entered some character or the file structure has been modified in something, we can cancel the changes by executing:
 : q! 

image

Step 3

In case of access to vim text insertion mode, which is accessed using the i key, if we want to exit this way because we are not going to enter anything or because we enter text but we regret it at the end:

image

Step 4

There, we can not use either: q or: q !, in this case we will use the Esc key with which we will go to normal mode and there if we can use the previous combinations. In case of having several files open using vim simultaneously and we want to close them in one step, we must execute the following:
 : qa! 

2. Save files with the Vim editor in Linux

Step 1

When the respective changes have been made to the current file, we can execute the following line to apply the desired changes in it:
 : wq 

image

Note
This obviously after using the i key to insert the text and use the esc key to return to normal mode.
Step 2

Another simpler option to save and close vim is to execute the following:
 : x 

image

Step 3

Some additional commands to exit vim are:
  • Press the Shift key and use the zz keys

+ z + z Shift + z + z

  • Press the Shift key and use the zq keys

+ z + q Shift + z + q


3. Open different Vim modes in Linux

As an additional point to what vim offers, TechnoWikis will explain how to access the different vim modes, these are:

Normal mode
To use the normal mode just execute vim or use the Esc key while in any of the previous modes:

image

Insert mode
If we want to use the insert mode with which the text of the file is added or edited, we press the i key and note that at the bottom is the legend "insert"

image

Commands mode
To use the command mode we must use the signs :. , thanks to this mode we can use functions such as search and replace with regular expressions.

image

Visual mode
If our plan is to use the visual mode we must enter the letter
 v 

image

We see how this editor is a useful and simple solution to carry out all the tasks of editing files of the different directories in Linux thanks to each of its tools and ways to work in a not only safe but practical way.


by (3.5m points)
edited

No related questions found

Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users