In this series we have been using Vim. Now, you don’t have to use vim if you don’t want. That’s fine. I too am very new to Vim, I just started using it this year. So I am still a beginner. When I first started using it, I found it to be very annoying, like it made everything more complex than it had to be. If you feel that way, I understand. One you learn some of the commands, you can see that it’s not so bad. One of the huge benefits of using vim is that it is so widely available. This means that if you have to connect to another computer through the command line, the chances are you can edit text files on the remote computer using Vim. Cool.
Let’s open a file in Vim.
The first thing I want to do with vim is make it not so ugly. The way we can do that is turn syntax highlighting on!
We can also add a line count:
This is great and all but watch what happens when we close and reopen vim.
You can see that the syntax highlighting and line count goes away. To fix this, we have to edit a file for our vim configuration. So let’s quit vim.
Put this in the file:
It’s okay if it is a new file. It should still work as long as we are in the home directory, which we are from running cd.
The next thing I wanted to discuss is the proper way to move the cursor around in vim. Let me open a small program to show you some commands. So far you’ve probably used the arrow keys to move your cursor around in vim. This is fine starting out, but a lot of people actually do it a different way. When you use the arrow keys, you often train yourself to stay in insert mode all of the time because you can move around while in insert mode. Well, you are actually not supposed to stay in insert mode but rather are supposed to only be in insert mode when you are about to type.
The recommended way to move your cursor around is with h, j, k, l. Give it a try and see if you can get used to it. Now, when you see something that needs changed, you are supposed to move there, then enter into insert mode, and then exit insert mode. Let’s give it a try.
Now, whether you use the arrow keys or not is ultimately up to you, but either way you will probably want to try to get into the habit of only being in insert mode when you really need to insert something and not all of the time. That’s because when you are not in insert mode there are other commands you can run to make coding a lot faster.
One of the easiest ways to move around is using G. Type a number followed by G to go to that line.
G by itself goes to the very end.
$ goes to the end of a line
^ goes to the beginning of a line.
a will enter insert mode after the character you are on.
w is used to move to the beginning of the next word
b is used to move to the beginning of the previous word
In the next video we are going to discuss how to copy and paste, undo and redo, and other cool stuff like that.
Support me! http://www.patreon.com/calebcurry
Subscribe to my newsletter: http://eepurl.com/-8qtH
More content: http://CalebCurry.com
Amazing Web Hosting – https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)