image
Exercise: Creating and Editing a New File with Vim

Contents

Vim Quickstart
1
Modes
PREVIEW2m 45s
2
Vim Quickstart
PREVIEW4m 32s

The course is part of these learning paths

Start course
Difficulty
Beginner
Duration
11m
Students
403
Ratings
4.7/5
starstarstarstarstar-half
Description

This course covers modes in Vim and looks at the command-line version of Vim. We then guide you through a demonstration of how to create and edit files in Vim, in order to provide with a practical understanding of the concepts and to give you the chance to try them out for yourself.

Learning Objectives

  • Get a basic understanding of modes as well as the command-line version of Vim
  • Learn how to create and edit files in Vim

Intended Audience

This course is ideal for anyone who needs to edit files in a command-line environment.

Prerequisites

If you want to follow along with the exercises in this course, you should have the Vim text editor installed on your computer.

Resources

If you want to follow along with the exercise(s) in this course, you can find the necessary resources here.

Transcript

Welcome to the first of many practice exercises in this course. I really want to encourage you to try these practice exercises on your own first before you watch these walkthrough videos and there are two primary reasons for that. The first reason is that I don't want you to get in the habit of just watching me perform the exercises, I actually want you to do them. Now, the reason for that is that doing is learning. If you actually do the exercises, you're going to actually retain more information. And so I'm really, really encouraging you to take the time to do those exercises. Now, if you're doing the exercise first on your own and you get to a place where you feel stuck, then turn on the walkthrough video, get to that point, see how I go through that situation, and then I encourage you to pause the video and then go back to the instructions and continue working on the project on your own. Now again, you can practice with this. You can try the exercises on your own first and then watch me, hopefully that's gonna work for you. If not, you can watch me first and then do the exercise on your own or you can even watch and do at the same time. Now I'm gonna leave that up to you, but again, I really encourage you to try it out on your own first. So let's get into this very first project. Now the goal of this exercise is to create a simple file and then edit it with VIM. You're also gonna get a little bit of practice changing in between the normal mode and insert mode as well as command line mode. During this practice exercise, you're going to create a new file with VIM, insert some text into that file and finally save it. So the first thing we're going to do of course is start a command line session on our local machine. Here I'm on a Linux system and I have my terminal up. Next, let's use VIM to create a new file named myday.txt. To do that, you can type VIM space myday.txt, press enter. Now, VIM is started. You now have a new file opened and you're placed into normal mode. To get into insert mode, you just simply press the I key, the lower case I, and now you're in insert mode. So let's go ahead and start typing and just write a couple of sentence about the beginning of your day as an example. Today, I woke up and fed my three pretty cats. So if you happen to make a mistake, let's say I said cats with a Z or something like that, I can simply just press the backspace key to remove that and then type over it again to make that correction. So if you make a simple typing mistake again, just back over it. Now let's continue typing some more information here. Let's enter in three things we're grateful for for today. Just hit enter a couple of times. And the first thing I'm grateful for today is my family. Oops, I made a mistake. Again, I'm just going to back up with a backspace key. Press enter to go to the next line. The next thing I'm grateful for is my health. I'm fairly healthy. Finally today, I am grateful for the warm sunshine that is shining through my window. Now once you're done typing, just press escape and then you return to normal mode or command mode. Now what we want to do is save our changes and to do that, we type colon to get into line mode or command line mode and then type WQ and press enter to save the file and quit. WQ, as you can remember, means right and quit. So we'll do that here, press enter. Now we can verify that what we've typed was saving the file by looking at the contents of that file. Of course, one simple way to do this is to start VIM again and look at the contents of the file so we'll type VIM myday.txt, press enter. And we can see all the information that we typed in this file and save. Because we aren't making any changes and we don't want to save any accidental changes, we can exit with colon Q exclamation mark, enter.

About the Author
Students
14171
Courses
61
Learning Paths
13

Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.