Index āŗ 3. Hello Kitten, revisited
Making changes to your first web page.
Topics covered
- Editing source files.
- TODO: Introduction to version control
Cha-cha-cha changesā¦!
Now that we have our shiny new tools, letās change (āeditā) our Hello, Kitten example:
Switch to the directory of our project, in case weāre not there already:
cd ~/small-web-course/hello-kittenFire up Helix Editor:
hx .Pick the index.html file from Helix Editorās file picker.
Weāre going to alter the code so it reads:
<h1>Four kittens</h1> <p>š±ļøš±ļøš±ļøš±ļø</p>Helix is a modal editor where you first select the thing you want to change and then issue a command to change it.
Press the left arrow and right arrow keys and you should see your cursor move left and right as you would expect from any other graphical editor.
However, if you press h and l, you will see it do the exact same thing, unlike what youād expect in a graphical editor, where you would expect āhā and ālā to be inserted in the text.
The reason
h and l move the cursor instead of entering āhā and ālā is because you start out in Normal mode, which is for navigating around and selecting bits of your code to manipulate.Also try the w and b keys to move forward and back one word of a time. Notice that the word is selected as you navigate this way.
Use the navigation commands you just learned to move your cursor to the
kinKittenand press the i key to issue the insert command and enter Insert mode with the insertion point right before where your cursor was.Type
Fourand press the Esc key to return to Normal mode.Next, letās make that āKittenā into ākittensā:
Your cursor should be on the
KinKittennow and we want thatKto be a lowercasekinstead. We have several ways we can achieve this:Press r for the replace command, and then type a lowercase
k.OK, that worked, but letās also learn a few other ways that will come in handy later.
First, undo what you just did by pressing the u key to issue the undo command.
The
Kshould be capitalised now and your cursor should still be on it.Issue the
switch_to_lowercasecommand by typing in a backtick (`). If you want to make it uppercase again, you can issue theswich_to_uppercasecommand by typing in Alt `Pretty cool, huh?
And youāre not limited to changing just a single character at a time either.
Press the
w key to select the whole word (kitten) and try issuing theswitch_to_lowercaseandswitch_to_uppercasecommands again. You should see the whole word change in response.This is the power of the select-then-manipulate model that Helix Editor uses.
Now, with the whole word selected (or with your cursor on the
ninkitten), issue theappend_modecommand by pressing the a key and type ansto make the wordkittens.Press Esc to return to Normal mode.
Right, weāre getting there. But it would be nicer if our two HTML tags (
h1andp) were on different lines so our code is easier to read. So letās enter a line break in between the closing</h1>tag and the opening<p>tag:Issue the
find_next_charcommand by pressing the f shortcut and then press> to find and jump to the>sign at the end of the closing</h1>tag.Press
a to enter append mode.Press Enter to enter a line break.
Press Esc to return to Normal mode.
Ok, the only remaining change we need to make is to replace one kitten with four.
Navigate your cursor so it is on top of the kitten emoji using the commands you learned earlier.
Press the y shortcut to fire the
yankcommand. This places whatever is selected in your source code on Helix Editorās internal clipboard.Press the p shortcut three times to fire the
paste_aftercommand so you end up with four kittens.Finally, we just need to save our file.
To do that, you have to call up the Helix command-line (think of it as a little terminal built into Helix Editor itself) using the : key and enter either
writeor, the shortcut,wand press EnterSimilarly, to quit Helix Editor, issue the
:quitor:qcommand.
Run kitten again and hit https://localhost in your browser (or refresh the browser window) to see it render your updated source code.
Next lesson: On HTML, CSS, and JavaScript (to be written)