Hello everyone in this lesson we will cover the Linux file editor and editor is a program which enables
you to create and manipulate data or text in a linux file.
There are several standard text editors available on most Linux systems.
You can use vi e d e x e x Pico nvm which is an album is the advanced version of vi in our lesson.
We will focus on Vi Y because VI is available in almost every Linux distribution regardless of which
Linux system you log in.
There's a buntu Susi read as sento as you're going to find VI everywhere.
Plus it's very easy to learn the vi editor actually supply's commands for inserting or deleting text
replacing text moving around the file finding substitute strings and cutting and pasting text inside.
So that's what we've done.
You have to write two four the most common keys are I should say to conserve escape replace before our
deeper delete and quit without saving and quit right and save.
So let's look at our Linux machine.
And at this time we will log into our Linux machine the Linux virtual machine through our session.
OK CD my and which DirecTV are in there a treat.
I want you to create your first file.
So call it the I which is a command space of my first added htar or just save my office for the munchies
you hit enter.
Now when you hit enter you are still in command mode.
You are not in insert mode.
So there are two different modes.
Once you are in the VI is first mode is to when you run the command second mode is when you inside at
the VI and you start typing it if you want to get out of that typing mode you have to hit escape.
So now let's start.
Let's see if I wired to type into this file you hit high or insert lowercase II as soon as you hit I
you see at the bottom it says insert.
It means we are in insert mode.
Now our regular Linux commands won't work we.
Because we are in insert mode so we could type something like.
Hello world.
This is my first lesson to learn.
Be-I and you could hit enter again.
I am so excited.
So it's just simple as if you're typing a word document.
Now if you wanted to exit out of it if you want to save this file all you have to do is hit escape right
here.
And once you hit escape you'll see the insert mode is gone.
Now how do you save this file.
You could do through two different ways one you hit shift Z Z the the twice and it will save the file.
Let's see if you can again and do my first file.
You'll see it's there.
And another way to save a file Let's go back in the file to my office and let's say you want typed something
hit insert again and then high space.
And now you want to exit out and say hey the escape and this time instead of shift Z Z you type shift
column right.
Quit an exclamation point which is all some refer to as bang you hit enter or do you where if you read
about my first file and there you go the file is there.
So this is these are the two modes is once you get out and once you get in.
Now I want you to go back into your file and it be and my first file and I want you to replace.
Hi.
Now I want you to delete Hi and leave that as is.
Now how do you go move around inside of a file and you are already in the editor.
You could use up bottom left right keys on your keyboard to move around.
But remember you cannot use these keys if you are in insert mode.
So let's say if you are hit I need you now to insert more.
And now you do the left right key.
It can work but it most likely it will break your commands so it's better you had escape and go back
and then you do d on your keyboard.
The
this will delete the entire line.
I wanted to delete only the word high.
So how do I get back.
My last line that I deleted.
So you hit you just simple you and it brings back your last line.
Now if you wanted to remove the high just type X once which will remove one character type X again which
remove another character.
Now you have a Space X again.
Now you don't have a space.
Now what if you want to save.
Now again to shift z z twice and it saves it.
How do you where you do.
Cat closed file and it is there.
Now let's go back in again and let's practice through replace command VI.
My first.
Now I wanted to replace.
I am so excited about it.
I want to replace the word excited with the word happy.
So how do we do it.
We cannot hit AI right now because we don't want to get into insert mode so we will use our arrow keys
to go down to the word excited.
So I could do our Once I had our I could do h.
It only replaced one letter.
If I wanted to do again the second letter you move your cursor to the right it are and then do a and
so forth.
But I would prefer that you do escape out of it and then do X X X X X and then you hit AI and then p
p y you hit escape again.
So you could move around and you can go up you could go down if you want to move around.
Now if you're if you want to go to the end of this file and now you wanted to create a new line right
below it before I'm so happy about it you had oh this will create a new line for you.
And also it will automatically put you into insert mode so you could type anything like la la la oh
you just noticed that you just typed J by mistake.
Now how do you remove J.
You type X.
Now remember if you're going to type x it will write X instead of deleting it.
Look see it typing the x y to delete that character would delete that kept this because you cannot delete.
Why because you are in insert mode.
How do I get out of insert mode.
You hit your say when Life-Saving key Midge's escape as soon as you hit escape.
You see the insert mode is gone.
Now when you hit x x it deletes those two characters that she added by mistake it was a typo that she
added.
Same way if you wanted to go up you could if you wanted to write something right here.
And if you type I notice it start writing right in the middle.
Hello.
Hi.
Without giving a space so let's do escape again.
X.
Move the cursor to the left and X and now you have that space in the middle.
Now how do I write.
By putting the space in the middle I do a.
So a will automatically advance to the next space.
So.
Hello hi bye space world.
Okay now you still insert more what if you want to save it.
Before you save it again get out of insert more by hitting escape and do shift z z.
This saved your bobcat.
First file and it is saving your first file.
Now what if I wanted to delete the line blah blah blah.
That third line.
So I'll go back to my Paul VI my first file.
Move your cursor down to blah blah blah and hit d d twice one too.
There you go.
It removes the line that you added that whenever you want to go if you want to.
You moved it by mistake.
No problem.
You will bring it back again.
You could save it to shift z z or you could save it through call right quit and bang you could hit enter
and that's how you set it up.
Now let's go back into the fall one more time I might post file and I want to let say I have a file
which is huge and I wanted to search for a specific word in a file.
Let's say I want to search for less than I want to search for.
So you can do search for it two ways.
I hope you remember the command graph and then you search for less than from where my first file and
only bring that one line that has the word lesson.
But if you are indeed IMO you could also do that same search and now you could just simply make sure
you are not in insert mode simply hit slash and type L he says or lessen it enter and there it will
bring you to exactly the word that you want to change.
Perhaps.
Are you looking for.
So these are the few commands that we have about creating a file using the IDE.
We do have many different commands or keys that we could use in vi.
I have included in this lecture I have included all those keys in and in as.
As in hand out.
So please look into those and try every single key.
I really want you to be very familiar with this and become eventually become an expert when you are
typing in something in your text file.
You know exactly which key you're going to work into or which key exactly key issues.
One common mistake that everybody is going to make is when you are in insert mode you're probably going
to have to get out of bed.
You can use typing x.
This and that but you cannot.
So is your life saver as you do colon now.
First sorry first has escape colon Q..
Now this time don't write w the W will write your changes to the.
You don't want to make changes.
So just to quit Colquitt.
Bang.
Hit enter.
Verify it.
There it goes.
Now you don't have that garbage that you were going to write your file into.
So this is another way you get out and change your file.
So please practice man.
Also give you different options to use it.
There is again there is another editor if you like to use which is which an advanced version of vi.
Or you could use that too which is also available most of the links or solution whichever you like but
please do practice practice as much as you can and I would recommend that you create files many files
in your home directories or within your subdirectories create your files and write whatever you want
to write ABC or write a story or whatever and change your text.
This is this is going to allow you to practice the editor.