Terminalo autobusai

How to use Vi editor in Linux (with examples)

How to use Vi editor in Linux (with examples)

Vi editor is short for the visual editor app and is a command-line based tool used as the default editor in almost all Linux distributions. It is similar to Notepad on Windows or TextEdit on macOS.

In this tutorial, we shall show you how to work with the Vi editor and the most important shortcuts to use that will help you effectively edit any file. Vi has three main modes that you can use including the Command mode, Escape mode, and the Insert mode that we will be discussing today.

1. Command mode

The command mode in the vi editor is the first mode you will get when you open up the vi editor. In this mode, every typed character is considered as a command. Hence, the vi editor will not display or show any of those commands in the window. Moreover, as long as you are in this mode, you can copy, paste, move through the file, or even delete some characters from the file. Additionally, if you are using any of the other two modes and need to return to the command mode, all you need to do is just press the [ESC] key from the keyboard.

To open a file in the vi editor, launch the Terminal and enter the following command:

vi filename

Where the filename may be a new file that will be created or an already existing file.

Create and Open Vi Test File

If you created a new file that is not already exiting, then you should get something like the below screenshot:

The Vi Test File Opened

You can use the following shortcuts:

2. Escape mode

To be able to use this mode, you need to first be in the command mode, then press the colon “:” character. Typically, during this mode, you can write any command next to the colon character. The forward slash can be used instead of the colon character, and that is in case you need to search the text in the file.

The following commands can be used during the escape mode:

Save and Quit File

Quit The File Without Saving

Quit The File.

Save The File

Search For a String

You can hit enter then the cursor will highlight the string you are searching for if it is found like the below screenshot:

The Result of Searching a String

3. Insert mode

In the insert mode, each keyboard keystroke will be dealt with as a text, and the vi editor will preview it on the screen as entered from the keyboard by the user. This is the mode where you will be allowed to start entering and inputting text into the file.

During the insert mode, you can use the following shortcuts:

Conclusion

That's all about the Vi editor and its usage in Linux. Hopefully, this tutorial helped you to get you ready to edit your files using the vi editor and effectively use its shortcuts.

„AppyMouse“ ekrano „Trackpad“ ir pelės žymeklis, skirtas „Windows“ tabletėms
Planšetinių kompiuterių vartotojai dažnai praleidžia pelės žymeklį, ypač kai įprasta naudoti nešiojamus kompiuterius. Jutiklinio ekrano išmanieji tele...
Vidutinis pelės mygtukas neveikia sistemoje „Windows 10“
The vidurinis pelės mygtukas padeda naršyti ilgus tinklalapius ir ekranus, kuriuose yra daug duomenų. Jei tai sustos, gerai, jūs naudosite klaviatūrą ...
Kaip pakeisti kairįjį ir dešinįjį pelės mygtukus „Windows 10“ kompiuteryje
Gana įprasta, kad visi kompiuterio pelės įrenginiai yra ergonomiškai sukurti dešiniarankiams. Tačiau yra pelių prietaisų, specialiai sukurtų kairiaran...