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:
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.
- Macro recording functions.
- Detection and conversion of file formats.
- Windows divided vertically.
- 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
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
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!
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:
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
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
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:
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"
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.
Visual mode
If our plan is to use the visual mode we must enter the letter
v
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.