In this demo, we'll be looking at pagers and the Vim text editor.
Now,
pagers are programs that allow you to open multiple pages
of text and navigate through them while on the terminal
and the two pagers that we'll be looking at are called less and more.
The first one we'll look at is less
and it has a little bit more features than more.
So now we've opened the file in a pager.
Here's how you can tell you're in a pager.
Sometimes other programs will put you into a pager. So this is good to know
one way to tell is that at the bottom left corner right here,
we have the file name highlighted.
But with the less pager,
you can use the arrow keys to move up and down through the file.
And you also have things like search functions.
For example, to search for text, you can press the slash key
and then you'll see that down in the bottom left hand corner,
enter the term you'd like to search for, I'll search for system
and this will search for it and show every time it's mentioned.
And you can see here it's highlighted where it occurs
to get to the next instance on a line where it would occur, you press the end key
and that will continue to move through each new instance of the search term.
But you'll notice it's skipping some of them.
And that's because it's case sensitive
to make it case, insensitive,
you need to pass in the dash I option
to ignore case
and then they will start getting all instances of system
and to move backwards through the previous results,
you would hold the shift key and press N.
So A capital N will move upward through the previous results.
And lastly to exit the pager, you need to press Q to quit.
So that's a brief overview of the less pager.
Now more doesn't have as many features but you access it the
same way type in more and then the file you want to read
and you'll see now that you're in more because it will let you know down at the bottom,
it will say more with a percentage
and with more, you move through things by pressing the space bar
and that moves at a page at a time and you
can see the percentage of the file that you're going through
and to get out of more, you press the Q key
so thats it for pagers.
Next, we'll move on to the Vim text editor
and Vim stands for V I improved.
So when you first open up Vim, it'll give you this nice little greeting screen
and it shows you a couple of things that you can
do with it and a few of the commands you can have
now Vim is mode sensitive.
So it has different modes to be in and different keys
and functions that are available depending on the mode you're in.
In order to write text into a file, you need to press the I key to go into insert mode
and you'll notice down at the bottom left hand corner,
it now says insert and you can start typing text.
So we have this as our text for our Vim demo.
And I'll put a couple of blank lines here,
right? There are some things you can do in insert mode.
You press the escape key to go back to the default mode or command mode.
Let's look at how we can create or edit files with them.
I want to create a new file called test dot text. So we type in Vim
test dot text
and we'll create a new file.
Now, if I want to go and save the contents of this file,
I'll press escape to go back to command mode
and type colon W to write to the file.
And one thing that folks like to joke about on the
internet is how to exit Vim how to close the program.
Well, here's how you do that
press escape,
then colon
WQ or write and quit
and it wrote to our new text file
and here's another useful tip. Let's open our file again.
Let's say we put in a bunch of stuff in here and we decide that, you know,
we don't want to save it.
Let's just start over again.
Well, you can quit them without writing
type in escape cue with an exclamation point.
And then we'll quit the file without saving any changes
to open an existing file. You type in Vim and then the file name,
here's a text that we created earlier.
And in this file, you can navigate with your arrow keys
or you can press L to move right,
H to move left
K to move up
and J to move down.
So there's a couple different ways to navigate and you don't need a mouse
now to search for something. You use the slash key just like you did in less
and you do this in default mode.
So I'll search for this
and
it doesn't find much because that's case sensitive.
If you want it to be case insensitive,
you can do this by following it with an escape character.
So what we're doing is putting in our search term,
then we put a slash the other way and put the letter C
think of C for case
and that'll make it case insensitive.
And there we go,
here's how you can go to a specific line number
by typing in a colon followed by the line number
great.
And now I want to go back up to line three.
Awesome
to copy an entire line of text.
When you're in command mode, you can hit the Y key two times, think of Y like Yank.
So we've copied this line
and then to paste that line of text,
you press in P while you're still in command mode
and it will paste that wherever you want it,
you can press P as many times as you want.
You can also cut a line of text by using the D key two times. So press DD
and that will cut it.
And then you can also paste things from anything you have cut.
So these are just some of the useful commands that you can use in Vim.
So that is a brief overview of the functions of less, more and Vim.
And I'll see you in the next lecture.