ericvlog / note

6 stars 1 forks source link

VI Editor with Commands in Linux/Unix Tutorial #21

Open ericvlog opened 2 years ago

ericvlog commented 2 years ago

What is the VI editor?

The VI editor is the most popular and classic text editor in the Linux family. Below, are some reasons which make it a widely used editor –

1) It is available in almost all Linux Distributions

2) It works the same across different platforms and Distributions

3) It is user-friendly. Hence, millions of Linux users love it and use it for their editing needs

Nowadays, there are advanced versions of the vi editor available, and the most popular one is VIM which is Vi Improved. Some of the other ones are Elvis, Nvi, Nano, and Vile. It is wise to learn vi because it is feature-rich and offers endless possibilities to edit a file.

To work on VI editor, you need to understand its operation modes. They can be divided into two main parts.

In this tutorial, you will learn more about-

@media(max-width: 499px) { .videocontentmobile {min-height: 280px; } } @media only screen and (min-width: 500px) and (max-width: 1023px){.videocontentmobile {min-height: 100px;}} @media(min-width: 1024px) { .videocontentmobile {min-height: 250px; } }

if (typeof(pubwise) != 'undefined' && pubwise.enabled === true) { pubwise.que.push(function() { pubwise.renderAd('div-gpt-ad-9092914-1'); }); }else{ googletag.cmd.push(function () { googletag.display('div-gpt-ad-9092914-1'); googletag.pubads().refresh([gptadslots['div-gpt-ad-9092914-1']]); }); }

Click here if the video is not accessible

vi Command mode:

vi Editor Insert mode:

@media(max-width: 499px) { .content2 {min-height: 100px !important; }} @media(min-width: 500px) { .content2 {min-height: 91px !important; } }

if (typeof(pubwise) != 'undefined' && pubwise.enabled === true) { pubwise.que.push(function() { pubwise.renderAd('div-gpt-ad-9092914-2'); }); }else{ googletag.cmd.push(function () { googletag.display('div-gpt-ad-9092914-2'); googletag.pubads().refresh([gptadslots['div-gpt-ad-9092914-2']]); }); }

How to use vi editor

To launch the VI Editor -Open the Terminal (CLI) and type

vi <filename_NEW> or <filename_EXISTING>

And if you specify an existing file, then the editor would open it for you to edit. Else, you can create a new file.

VI Editing commands

Note: You should be in the “command mode” to execute these commands. VI editor is case-sensitive so make sure you type the commands in the right letter-case.

Make sure you press the right command otherwise you will end up making undesirable changes to the file. You can also enter the insert mode by pressing a, A, o, as required.

@media(max-width: 1023px) {.content61 {min-height: 91px !important; }} @media(min-width: 1024px) {.content61 {min-height: 280px !important; }}

if (typeof(pubwise) != 'undefined' && pubwise.enabled === true) { pubwise.que.push(function() { pubwise.renderAd('div-gpt-ad-9092914-6'); }); }else{ googletag.cmd.push(function () { googletag.display('div-gpt-ad-9092914-6'); googletag.pubads().refresh([gptadslots['div-gpt-ad-9092914-6']]); }); }

Moving within a file

You need to be in the command mode to move within a file. The default keys for navigation are mentioned below else; You can also use the arrow keys on the keyboard.

Saving and Closing the file

You should be in the command mode to exit the editor and save changes to the file.

Summary: