hi I'm going to show you a little bit
about how to use VI or VY or VI M or vim
as you might want to call it text editor
you might want to use this as if you are
at a logging into a server or something
anyway to get there you type VI or VI m
and then the name of the file that you
want to edit I'm going to edit this file
called index.html and as soon as I type
that it opens up an editor now my mouse
is no good at this point so to move
around you simply use the arrow keys and
something to know about VI is that you
are always in some certain mode as they
call it and right now we are in what is
called normal mode I'm going to show you
how to move around to the different
modes and just do some basic editing the
only thing that stinks about VI is that
you can wind up getting the file all
goofed up and then you don't know how to
get out of the file and you're afraid
you're going to save something so I'm
going to show you essentially what is it
the panic button and that is you hit the
Escape key I'm hitting the Escape key
you can hit it as many times as you want
until you start to hear you might hear a
beep or something that means we're back
in normal mode you can always just keep
hitting escape and you'll wind up back
in normal mode and then once you're in
normal mode you can enter commands and
the command that we're interested in is
you : so now we're in going to enter a
command and you can see that down here
and then a Q followed by an exclamation
mark Q means quit and the exclamation
mark means forced quit so even if there
are any changes to the file and that's
important because if you sort of get
lost which you can do this is just like
they do over so now we are we didn't
save anything that's what I could
consider the panic button and that is
helpful even for me at this point so
anyway we're in normal mode here I've
opened the file back
and really to do anything know we need
to go into some other kind of mode so
there's a insert append and replace are
probably the main ones that you would
use insert and append are essentially
the same thing it just means start
inserting where you're at and I'm gonna
do that here so I hit the I and the keys
are I for insert a for append and are
for replace so they're pretty easy to
remember so I'm gonna if I hit I here
you can see down there it says I'm an
insert mode and I can start typing there
we go and then when I hit escape now I'm
back in normal mode so I can move around
this important thing is once you're
finished typing you always should hit
escape so that you can go back to moving
around now append mode you don't notice
the difference so much until I'm at this
last character here if I type I and I
start typing you see the the arrow is is
not moving I just undid that I hit
escape and I pressed you and that undid
the typing what I really wanted was to
say insert at the end of this line so I
need to type a that means start
appending after where I'm at so okay so
that is insert and append and in
addition to the lower case I and lower
case a you can do the upper case I and
upper case a and it's the same thing but
it just has a convenience of moving you
to the beginning or the end of the line
so I'm gonna hit upper case I see it
moving it at the very beginning and I'm
gonna hit escape and I'm back in normal
mode and if I hit shift a capital a it
puts me right at the end of the line and
then escape and I'm back in normal mode
now to replace it's a little bit
different the lowercase R only goes in
to replace mode for one character so I
can type r and then I'm going to just
type another letter so let's just say Z
you can see it replaced that T with a Z
right there but I'm no longer in edit
mode it's just a one character so it's
not super useful but if you hit shift in
are it just goes into sort of permanent
replace mode so I'm gonna hold shift and
are down now I'm in a replace mode and I
hit escape and I'm back out there we go
so I can even insert put in another
space so that's the basics of just
getting stuff in and now deleting is
something that you would need to do -
this is typical editing here to delete
first get yourself into normal mode hit
escape and if you hit the X key it will
delete right at the character where the
cursor is via X X and I don't actually
go into insert mode at that point I'm
just in normal mode the whole time
deleting everything there we go and if I
wanted to delete this whole line well
I'm still in normal mode you hit D twice
so D D so here we go d D the whole line
is gone
another thing is sometimes you want to
sort of delete this line break at the
end of this line that's actually called
join and the key to do that is capital J
for join so you hold down shift and J
and it happens the previous line on with
the next line I sort of consider that a
delete because we're deleting the line
break at the end of the line so now that
I'm finished editing this file I want to
save it so again you can always hit
escape I keep repeating that because I
hit escape a lot just to make sure I'm
in normal mode and then you hold down
Shift + ZZ so you hit the z key twice
while holding down shift shift Z
that saves and exits so we just save the
file if we open it back up we can see
here the you know the title that I
deleted and the meta tags are right next
to each other so that's your basic
editing and the next thing that you
probably would want to do is to search
through a file so to search you do that
using either the forward slash key or
the question mark and for me I always
just use the forward slash it basically
means search forward or backward I just
use the forward slash I mean search for
word and so we'll say I'm gonna look for
dot CSS and when I hit enter it takes me
to the first occurrence of CSS there and
now if I want to go to the next result
or the previous result I just use in for
next and then shift in for previous so
here you can see it taking me to the
next and then it's told me that we've
reached the top of the file and it's
going through I'm just still hitting the
end key and if I hit shifting in there
we can see it's going up so I can go and
that's really important to know how to
search through a file when you're in
here now on to the next more advanced
topic copy and paste which is another
thing that's handy to know how to do so
you've got a couple of choices for copy
and paste you can either just copy an
entire line or you can copy a selection
but I want to copy this entire line I
hold down Y twice I hit it yet Y stands
for yank and it means yank whatever the
contents are into a register so I YY
doesn't show me anything but then if I
move down to the next line I can hit P
for paste or put as they refer to it P
and it's just pasted that exact line
there if I only want to copy a little
bit though I need to select some text
and to select text you use the V key
which actually stands for visual mode
but if I hit the
then you can see that I'm in visual mode
down at the bottom and I move the cursor
over to just the end of here let's say
okay and then I hold down Y and that
copies whatever is selected into the
buffer I'll give myself a couple of
lines and then I hit P again and there
we go
so we've gone through inserting deleting
opening files searching copy and paste
those are just about everything that
you're gonna need to know to do just
about any type of editing that you would
want but I'm gonna show you one more
advanced feature and that is dealing
with Windows so to give you something
that's actually really helpful I'm in
normal mode if I hit the colon and I
type VI usage VI usage you see I have
two windows now and the top window where
I'm at is actually shows you all of the
commands so this is really handy to keep
open because you can use it as a
reference and but I need to know how to
switch windows so when you're when you
want to issue a window command you just
hit control W and then the next thing
that you type will be a window command
and so when I press ctrl W now I can
either press the arrow up or down and it
will move to that window so you can also
use the letter T in the letter D for top
window and bottom window but the arrow
should work so once again now I'm in the
file that I'm editing and all of the
normal commands apply it's just like two
windows open side by side so I can go to
control W and go back up to this window
it so now I'm back in here and I can
search for
I can search this file for let's just
say search there we go so you can see
right there it just it just took me to
search and I can hit the N key and it's
telling me the keys that I need to
search so that's a really good thing to
know and then when you're done with this
window you can do the : Q and since we
didn't make any changes we don't need to
put the exclamation mark but we can
anyway and then we're back to just one
window so that's how you navigate
windows and how you actually open up a
file reference for yourself and if you
want to open your own files up in
multiple windows I can say VI M - o
capital letter and let's say I want to
open up index.html as well as dot h TX s
at the same time so I have two windows
ctrl W goes into window mode and I can
flip between the two if you can see the
there we go I'm in the left one now if I
hit ctrl W left arrow now I'm in the one
on the left
so I'm editing two different files side
by side and whichever one I'm in again
the commands apply so let's say I'm done
editing this and I wanted to save it
shift is easy and I'm left with one
window if I shift is easy that there we
go alright so I hope that was helpful
showing you how to use VI thanks for
watching I'll see you next time