Task 2: Running the Vim Tutorial
I started by running the vimtutor application to learn the basics of
Vim, which is one of the text editors available in Linux.
From my location in the terminal, I entered:
vimtutor
and pressed Enter to start the vimtutor session.
I had to use sudo for this step since I wasn't logged in as root. When
vimtutor didn't work initially, I needed to install Vim by entering:
sudo yum install vim
I then completed lessons 1-3 in vimtutor, which taught me the
fundamental operations in Vim.
The terminal window displayed the vimtutor output, starting with
tutorial lesson 1.1 about moving the cursor. I could see that vimtutor
consists of tutorials designed to teach users how to use Vim
effectively.
When I was done, I entered :q! and pressed
Enter to exit vimtutor.
Task 3: Editing a File in Vim
Next, I used the Vim command-line editor to create and edit a file
through the following steps:
-
From my current location in the terminal, I entered
vim helloworld and pressed Enter. This
created a new file called "helloworld" and opened it.
-
Once inside the file, I needed to enter insert mode to add text. I
pressed i to enter insert mode (I noticed
the bottom left of the terminal indicated I was in insert mode), and
then typed:
Hello World! This is my first file in Linux and I am editing it in
Vim!
- After typing my text, I pressed ESC to exit insert mode.
-
To save my changes and quit, I entered the command:
:wq
-
I then reopened the file by typing:
vim helloworld
(I found I could use the up arrow to recall this command since it
was the last one I used)
-
I added another line to my file:
I learned how to create a file, edit and save them too!
-
Once finished, I pressed ESC to exit insert mode and entered:
:q!
This returned me to the main terminal.
-
I went back to the helloworld file with Vim to analyze what happened.
The difference I noticed was that when I used
:q! instead of
:wq, my changes weren't saved - this
command quits without saving.
Additional Vim Commands I Practiced
I also tried these useful commands:
- dd - Deleted the entire line
- u - Undid the last command
-
:w - Saved changes without quitting
Task 4: Editing a File in Nano
For this task, I used nano, an alternative command-line editor, to
create and edit a text file.
-
Similar to how I used Vim, I entered
nano cloudworld in the main terminal and
pressed Enter. This created a new file called "cloudworld" and opened
it.
-
Unlike Vim, I didn't have to enter any special mode to start typing in
nano. I immediately typed:
We are using nano this time! We can simply start typing! No insert
mode needed.
-
To save my changes to the file, I pressed CTRL+O and then pressed
Enter to confirm the filename.
- After saving, I pressed CTRL+X to exit the nano editor.
-
To verify that my file saved correctly, I went back into the file by
entering nano cloudworld I confirmed
everything was correct and then exited the editor by pressing CTRL+X
again.
I found nano to be more straightforward than Vim since it doesn't use
different modes for editing and navigation. The commands are displayed
at the bottom of the screen, making it easier to remember what to do.