In the last blog we talked about some tricks when it comes to moving around in Vim! This blog is going to teach you even more important things to help improve your efficiency. Are you new here? Start at the beginning, Intro to C!
The first thing I wanted to talk about was different ways to quit the application. The very first is
This is how you quit without saving. If you wanted to save your changes you could have used :wq, for write and quit, or a short cut is just ZZ without the colon. You should also know that anytime we have a : in our command it allows us to type out a larger command where we actually have to press enter. The other commands we learned about in the last video we didn’t have to press enter and they didn’t show up on the screen like this.
Now let’s reopen it.
What if you want to be able to temporarily close Vim without having to decide to save your changes or not? Kind of like just keeping it open in a new tab or something? Well you could always open a second terminal, which we may do at some point, ha!
But the more professional way is to use ctrl c. This will put Vim in the background and to bring it back up you type fg, for foreground.
Occasionally when working with vim, you might close the program wrong or your computer shuts down and the next time you try to open a file it gives you a warning message saying you were in the middle of working on the file. If that ever comes up, you’ll probably want to hit R for recover. We haven’t experienced that yet and as long as you are careful you should be able to avoid it as well.
Now, whenever you mess something up big time in Vim, you can undo using
You can redo using
You can cut using
This will put whatever into the clipboard. The clipboard is the place where things go when you copy or paste them. Yeah, I have no idea where the clipboard actually is, but it’s there.
To paste after the cursor
You could also use a capital P to paste before the line.
To delete the remainder of the line, use
Remember from the last video, $ is the end of the line.
To copy the line you are on, use
You can often mix these commands with numbers. So to copy 4 lines, use
That should be enough commands to get you started. Now, like I said, I’m still a complete beginner with Vim, so be patient with me. I’ll share a page with you that has been helpful to me.
Ready to move on to the next blog on data types? Let’s go!