Beginners Guide to Programming: Part 3 Unix Command Line and Vim

For anyone reading part 3 I am assuming you have already read at least part 2: environments . Which means you know that we will be working from the command line and using vim for this series. I would like to re-iterate that the command line seems "hard", but that is only because it is unfamiliar and does correlate well to real life examples. The command line is actually quite simple to use and users can get by with a only a couple of commands if they want too. The real reason the command line is difficult is because most people try to teach way too much way too fast. Today, we are going to start with navigation and file creation. Then we will look at getting around in vim. Note: If you want to use a mouse insert gvim everywhere I use vim. Gvim actually contains all the same tools as vim, but also has a GUI interface hence the G in Gvim.

To get started if you are using Ubuntu, Click applications -> accessories -> terminal. If you are windows click start -> run and them type cmd. You now have your command line interface running. The first you want to do is type ls. This will list(ls) all of the directories (directories are folders) and files in your current location. Most of the commands I give you should be written down and attached to your monitor for quick reference. ls is a command you will use often especially at first. Now that you see all the directories choose one to go to. It doesn't matter which. In my ls I saw the following

Desktop Documents Examples Music Pictures Public Templates Videos

Lets go to Documents this is done with the command "cd Documents" , if you want to speed up the process type "cd Do" then hit the tab key. The tab key will auto fill the rest of the name. "cd" literarly stands for change directory. Now that we are in documents lets see what in there with you guessed an ls. Well there is nothing intersting in Documents folder so lets go back to last folder by typing "cd .." this command will always take you back by one folder. If you want to go back two folders type "cd ../.." . The final command you must have is "pwd", this command tells what folder you are currently in. If I type pwd it returns:


You should probably fiddle around with these few navigation tools until you get the hang of making your way around the command line. Remember for your quick refernce guide place the following some where visible:

cd (place directory name)

cd .. or cd ../.. cd ../../.. ( go back one or two or three directories )

ls ( list all files and directories in the current directory )

pwd ( Current directory )

Once you are able to hobble around the command line it's time to jump into vim , once again if you are too afraid of text only type Gvim when I type vim. Let's create a new directory the needed command is " mkdir practice " and then we will enter it with "cd practice". Now that you are in a new clean directory type "vim practice.txt" . This will simultaneously open vim and create a new file. There is no requirement to enter the file type at the end of a file, but it is very helpful for organization. I suggest you give all files the proper type all the time.

Now, that you are in vim with open file its important to know that vim will not hurt you. If you ever get really messed up hit "esc" until you hear beeping. Let me explain how vim works. You start in command mode, there are many modes and each are reached by typing a letter in. The mode that is most often used is Insert, you reach insert mode by typing "i". Once again, if you hit some other key and get into a weird mode just hit escape. Once you are in insert mode you should be able to type like a regular word processor. Use the up and down arrows to get around to different lines. If you chose the Gvim option just click with mouse. You should now just spend some time getting comfortable in vim. Type up a paper in it or something. Your most important commands are save and exit. To save your file you must hit "esc" and then type ":w" and then hit the enter key. You have now saved your file. To make it back to the command line hit "esc" and then type ":q" and hit the enter the key. To exit and save hit "esc" and then type ":wq".

From now on I will assume you know at least this much about vim and unix. I will be dropping little tid bits of knowledge as I go along with the rest of the series. I hope you practice getting around the command line and vim. The next post we will start with a little programming and theory.

As usual this post is meant to be interactive and I would love to see comments. The more comments we get the more everyone gets out of the series!

Spread The Love, Share Our Article

Related Posts

1 Response to Beginners Guide to Programming: Part 3 Unix Command Line and Vim

May 4, 2009 at 9:02 AM

[...] move into other programming languages, just change syntax.  If you haven’t read Steps 2 and 3 please do so [...]

Post a Comment