Monday, April 22, 2024

Up Your Coding Game, VI Guide - Hacker 's Text Editor

We live in a time when time is the most precious resource, when everyone is in a hurry somewhere, when even developers look for shortcuts, when even some Linux users avoid using the Terminal emulator, except when they have to; surrendering to a more modern and attractive desktop graphical environment. And then we wonder why younger generations are not interested in some outdated text editor that is used directly in the Terminal emulator, where you even have to learn convoluted commands to type the most trivial text. After all, why not use the nano text editor, or even better, some modern graphical one if we really must?

Who has the time today to learn and practice using the most trivial text editor? The first reason is, believe it or not, so that you wouldn’t be a ‘Goddamn crybaby’ in the world of Linux users. Not to mention hackers, for them, it is unacceptable! Knowing how to use the VI text editor is a real art, and that is not the only reason why it is favored among the greatest hackers in the world, but because it is primarily a tradition, because it is encountered even in the oldest Unix variants, it is simply available. It is also useful because the POSIX - a standard for program compatibility on Unix systems requires that VI be present, despite the fact that its use requires learning and experience.

Otherwise, VI can save you when you find yourself in a situation where you are working on systems that do not have graphical environments, such as some remote servers or local systems. It can also be used as an IDE – integrated development environment for programmers. In today’s Linux distributions, VI is increasingly rarely installed in the basic package, but it can always be downloaded and installed from its official web page. See here. For example, the Kali Linux distribution Linux-ax has VI installed as VIM, an enhanced derivative of the original VI text editor, but not gVim, a text editor that has all the functionalities of the VIM text editor with its own graphical environment.

VI, Vim - Hacker's Text Editor

VI, Vim - Hacker's Text Editor

VIM can also be installed on all other platforms. On the Windows operating system, it can run in a graphical Windows window or be used in the Command Prompt. The first version of the VI program was written by Bill Joy in 1976 while he was a student at the University of California, Berkeley. VI is an abbreviation derived from the word ‘visual’ because the program was supposed to enable text modification on a video terminal using a movable cursor. However, its significant improvement was created by Bram Moolenaar.

Considering that you cannot just start the VI text editor and immediately type text as you want, because you must constantly switch between different modes of operation and use certain commands with text work; compared to other simpler text editors, you need more habit than less training to use it with ease. VI was created to be light and fast, designed for quick typing because you do not have to lift your hands from the keyboard while working with it.

Currently, as we write this text; most Linux distributions instead of VI mostly use the VIM derivative, its enhanced modern version 9.1.16 runs on both VI and VIM commands in the Terminal emulator. Unlike the VI text editor, its derivative VIM is free and open-source software, which is also issued under a license that contains some clauses that encourage users who enjoy the software to consider donating to children in Uganda. The license is compatible with the GNU General Public License through a special clause that allows the distribution of modified copies under GNU GPL version 2 or any later version.

VIM for Beginners: How to Get Started and What Commands You Need to Know

When you first start VIM by using the command VI or VIM in the terminal emulator, it opens VIM in normal mode. Unlike other text editors, VIM has modes that represent different functionalities. Without these modes, VIM wouldn't be able to distinguish whether you're typing a letter or a specific command. These are the basic VIM modes:

  • Normal - Normal mode is the default mode in VIM. It allows you to navigate through the document, delete, copy, paste, move the cursor, search, and execute various commands.
  • Insert - Insert mode is used for typing text.
  • Visual - Visual mode enables text selection. You can select a block of text using the mouse or by moving the cursor and apply commands to the selected portion.
  • Command - Command mode is used for entering special commands. You can activate it by pressing colon ":" in normal mode.
  • Select - Select mode allows you to select text using the mouse.
  • Etc.

So, for example, when you want to type text, you must be in insert mode for typing. However, to save the text you've written, you need to exit that mode, switch to normal mode, type colon ":" to enter command mode, and then type a lowercase "w." If your text file doesn't have a title, you need to add one. For example, two consecutive commands in normal mode would look like one extended command: w: text.txt In the VIM editor, you can execute multiple commands by typing them one after another.

Kali Linux, VI, VIM insert Mode

Insert mode in the VIM text editor is used for typing text

It would be best for you to try VIM out yourself right away. Launch the Terminal emulator and type the command vi. Then press the lowercase letter i or the Insert key on your keyboard, and you'll enter insert mode. Type some text, for example, "This is some text!" or "Hello World!" Then press the ESC key to exit insert mode and switch to normal mode. From normal mode, you'll switch to command mode by typing a colon ":" before your command, followed by the letter w and the filename to write and save your work.

:w text.txt

Next, type the following command:

:q or :q!

if there's an error.

Once you've closed the VIM text editor, you can reopen your text.txt file created in the VIM text editor using the following command in the Terminal emulator:

$ vi text.txt

Your text file will open in the VIM text editor. Close the VIM text editor afterward.

Kali Linux, VI, VIM - Read Text From Terminal

Display the contents of text.txt, a VIM file in the Terminal emulator

Basic VIM commands every developer should know

VIM has a plethora of commands, and it will take you a lot of time, effort, and practice to try them all in your daily activities. But once you get the hang of it and become accustomed to jumping from one mode to another, it will feel strange to later use a regular text editor. As for coding and programming with the VIM editor, it can be a bit more complex because you're dealing with Linux Terminal commands, VIM commands, and programming language commands. For an experienced Linux user, programmer, or hacker, this isn't much of an issue, but for every beginner, it will take quite some time. You can download a Vim Cheat Sheet - a list of VIM commands - in *.pdf format and view it here. If you want to install the VIM text editor on a Windows operating system, you can watch the following video.


Windows - 31. How to install VIM on Windows?


Windows - 15. How to install gVIM ?




 


 

No comments:

Post a Comment