So yes, we have to dive out to our command line,
but we're diving out to the command line on our host system,
not the virtual machine.
We're going to enable modeline within Vim so that we're able
to identify the syntax highlighting we need for files that
are not easily identifiable.
We're going to create ourselves a new Vagrantfile.
The Vagrantfile describes our virtual machine and is written in Ruby.
By adding in the correct modeline,
we're going to be able to identify that this is a Ruby file and
show the correct syntax highlighting and the correct configuration
that we need to easily edit Ruby files.
Come on, let's find ourselves a command line.
So here we are at the glorious command line.
Let's just go through and make sure that we know what we are doing.
The first thing that we're going to do is create or edit, a .vimrc file.
This then can control the operations for Vim.
If you're using different editors, then it doesn't really matter about this,
but this is a really good feature that we can add into our Vim text editor.
So if we edit the .vimrc file and we're going to go
through and configure set modeline, so that's going to enable it.
But whilst we're here, I can also go through and put bg=dark,
so we've got the correct syntax highlighting for a dark screen.
We can have dark or light.
If you've got a light screen, then don't set this configuration,
set it to light.
The main thing that we're looking at the moment is the modeline.
If I go back into that file,
you can see how setting a dark background then gives
me a lighter syntax highlighting, so it's easier to see on the screen.
In any case, we're ready to go with this.
And we're now going to create ourselves a project
directory for our web application.
We need to go through and I'm going to create then mkdir ‑p.
We might as well call the directory apache.
I'm going to have a subdirectory within that called web.
We don't need the web directory at the moment.
Later that is going to contain our web pages,
but for the moment, I'm going to concern myself just with the apache directory.
So I move into the apache directory, and,
of course, we can see it contains nothing,
but that empty web directory.
We can create ourselves a new Vagrantfile.
Vagrant init becomes a really good way to do this.
‑‑Minimal then gives me less documentation inside of my Vagrantfile.
To be honest, it probably becomes easier to work with.
And we're going to base our virtual machine on the ubuntu/focal64 image.
So that's created my virtual machine definition file, the Vagrantfile.
If I just run ls,
it is just called Vagrantfile, and without any other elements to identify it,
it would be difficult to know that this is actually a Ruby‑based file.
If I go through then and edit this,
we can see then that I just get plain white on black text;
I don't get any syntax highlighting.
So we're going to correct this.
Now obviously, I could just edit the file,
but we want to learn to do a little bit more.
So editing a file is easy, but learning sed is really useful.
We're going to use our stream editor, ‑i,
so we do an in‑place edit, so we are actually editing the file.
And we're going to go through and open up our single quotes, and on line 1,
we're going to insert a new line, so we're adding a new line to the file.
And this is going to tell Vim through our modeline that we have just edited
what we need to go through and syntax highlight this file for.
So we can go through and specify a comment.
The line will be a comment, so it's not going to be read by Ruby itself.
We're going to specify that we can use it for vi or vim,
it doesn't really matter, and then colon.
And then we define the settings that we want.
So we're going to specify our ft=r.
It's all colon separated.
So I'm going to use then the tb=2, so whenever I use the tab key,
we're going to move two spaces.
We're also going to use auto intent, so when I hit the return,
I go to the last indent level,
and that last indent level is controlled by my shiftwidth,
which I'm also setting to 2.
They're the only settings that I need to make so I
can go through and close my quotes.
And with this done and dusted, we need to edit the Vagrantfile.
We want to insert this modeline inside of my Vagrantfile.
Now that's it.
It's as simple as that.
Remember,
sed is editing our text stream so we don't get into
an interactive editing session.
If I now go back and open up my Vagrantfile,
we can see now that I've got glorious technicolor.
The first line being the comment is my modeline,
and we're reading the configuration settings that I need
to tell vi how to deal with this file.
We can see that I've got the correct syntax highlighting.
If I move down to my config.vm.box line and if I use uppercase A,
I move to the end of the line.
We can see my cursor now on the end of the line and hitting return,
we can see now that I'm indenting the information.
I haven't had to hit the tab key.
We've moved back to the previous indent level.
Now for the moment, we don't need to add in any configuration,
so I'm just removing that information,
and I can go through then and make sure that my file is saved.
But we've been able to add configuration information through to our Vagrantfile,
and we just include that line in each of our Vagrantfiles.
It becomes a very easy way that we can get the
correct configuration that we need.
Next up, we're going to be taking a look at how we can extend this Vagrantfile,
but for the moment, let's just check that is working.
Remember, this is for deploying our virtual machine,
so I'm going to use then vagrant and up.
And we can see then that we have not affected the
Vagrantfile by adding in the commented line.
We're able to read it properly,
and we're starting then to import our virtual machine.
I'm going to leave this running,
but we'll return to the slide to start looking at how we configure our Vagrantfile just a little bit more.