what's up guys as you can see we're back
in them and today I'm gonna be showing
you another whole mode in them called
visual mode visual mode is an extremely
useful mode for editing arbitrary trunks
of text inside of a file and there's
actually three different subtypes -
visual mode there is the regular visual
mode that people usually find first
which is really more of a visual
character mode you access it from normal
mode by pressing lowercase V on your
keyboard or just V as long as you're not
holding shift or having the caps lock on
and what this does much like how its
name sounds is it allows you to visually
select characters now when you enter
into visual mode of course it's going to
tell you down here since our mode has
changed it's going to change to visual
or it'll show up somewhere in your vim
file depending on how you have your vim
RC configured mhm
so in visual character mode we're able
to visually select characters one by one
so if I start hitting H you'll see that
I'm going over to the left from the area
that I originally was at and what this
allows us to do is just select whichever
characters are underlined so if I were
to hit Y then I will have just yanked
the text mode equals V and let me go
ahead and paste this on a new line to
show you that it really did yank and of
course you can do other type of actions
in visual mode as well if I wanted to
delete all of this I can go back into
visual mode and the same movement
patterns from normal mode also apply and
visual modes so I can select more of
this by doing W to select the whole word
or I can do capital
w-which believe did the same thing in
this instance or if you want to just
visually select to the end of the line
you can do dollar sign and like I said
the same actions that apply a normal
mode will also work in visual mode just
on the text that you've selected so I
can do D to delete it if I want or I can
just do X if I don't want to actually
yank that into my register
now speaking of lines there's another
type of visual mode called visual line
mode and this is accessed by doing an
uppercase V so try not to get confused
between the two different modes because
they are indeed very different visual
line mode will select the entire line
that you are on and of course you can
also go up and down with this you can
try moving around inside of it but
there's really not a whole lot of
purpose to do that in visual line mode
since it's just gonna select the entire
lines that you're on and keep in mind
that this will select literally the
entire line so if you have a line like
this with a bunch of whitespace and then
some characters in between it and then a
bunch of white space at the end you see
it's going to select everything
including this here which is actually
the newline character that's why if you
delete it it's not just going to leave
you with a blank line it's going to
leave you with that line being
completely gone and the final type of
mode for them which is actually well the
final type of visual mode which is
actually what originally got me really
interested in them is the visual block
mode now this is accessed again from
normal mode but you want to do ctrl +
lowercase V this time and you'll see
that we've entered visual block mode
and this is very similar to the regular
visual mode but the difference is that
it actually allows us to select text not
just in the left and right direction but
also in the up and downs election so it
basically lets us select text in a block
wise way which I guess is why it's
called visual block mode and one really
cool thing you can do with this let me
go ahead and open a new tab and show you
guys what actually got me so interested
in this feature of them so I'm gonna
open up this file so this is a real life
use case of what I've had to do in my
job before is sometimes we need to have
a list of phone numbers and pass it
through a program to do some type of
provisioning or some other type of work
with the phone numbers but all of the
tools we use don't have input validation
which basically means that the program
only expects a very specific type of
input so all of these phone numbers as
you can see don't have a country code to
them now it shouldn't really matter
because there's 700 numbers so they're
not real anyway but I know one program
in particular that we used would not
accept these because it doesn't have the
country code and also it has hyphens
inside of it which for whatever reason
makes the particular script that we
would use not work correctly so the way
that my colleagues were fixing this type
of stuff before is they would open up an
excel file and they would do ctrl H to
just find and replace all of these
hyphens
with a blank space which works pretty
well I mean you would pretty much do the
same exact thing in them but in order to
get the
country code at the beginning of all
these phone numbers well that would be a
little bit trickier if you wanted to do
that in Microsoft Excel
I believe the method they were using was
to just create one column like column a
and just put a bunch of plus ones in
there and then you'd have to do special
formatting to it or not really special
but just format it as text because
otherwise Excel things that's a math
problem and it wants to try to add one a
bunch of times
and then they would put the numbers in
the column to the right of it and then
do some type of concatenation to get
them together but thankfully in vim we
don't have to do all of that all we
really have to do is go into visual
block mode and then select all of the
numbers that you want to prepend
something to which in this case is going
to be all of them
so I'm just gonna do G to go to the
bottom and then you can do uppercase I
to start editing from the beginning of
the lime and you can place a 1 now
here's where the magic happens
because we entered into insert mode from
that visual block mode anything that we
type in this insert mode is going to
apply to all of the lines that we
selected so if I want to add a plus and
then the country code to it once I hit
escape to get out of insert mode you see
that it just applied it to all what is
this 41 or 42 numbers I think it's 42
numbers and then of course we can do the
same thing by getting rid of the hyphens
now this technically isn't the best way
to do this I guess find and replace
inside of them would be the best way to
do it but I'm just gonna do it this way
to basically showcase what you can do so
you can delete text from visual block
mode as well
and you can even append text to it as
well and you don't have to go to the
very end either you can just do dollar
sign to go to the very end or a zero to
go to the very beginning and then I'll
do uppercase a and whatever you type
will get applied to all the rest of the
numbers all right guys so that is visual
mode and them you've got your visual
character mode visual line mode and
visual block mode be sure to leave a
like on this video and share it with
someone else who you think would find it
useful peace out guys