Using Vim basics:

Written by : Gore

A Mini tutorial on using Vim.




Vim has a reputation for being hard and some senior members of Anti Online even say it's just hard to use and doesn't seem to work. Well, they said that about Slackware and Free BSD and I've written tutorials to help with all of them as well, so Vim can now be added to the list.



Why use Vim?


Vim is Vi Improved, it's got little changes from the original Vi.

Using it can be hard at first but when and if you get good at it, it makes editing text really easy because it loads fast, is stable as hell, and to be honest I've never seen it crash even when editing HUGE txt files.

Another reason to use it is because editing UNIX system files, well, they have to be plain text, if you opened them up in Word they would be destroyed.

And of course, Emacs and Word are NOT on any UNIX recovery disks. If you mess something up on your system bad enough, you're going to either learn to use Vim or reinstall.




Basics:


To start Vim, simply open a bash shell, or if you're already in text only mode, just type "vim" at the prompt. you can have X loaded too, but Vim doesn't require a GUI to run.

After you type vim you'll see it loaded with usually some form of text saying something about what version you have or something else.

Now when you start typing it's just going to beep at you. when you first satrt vim you're in "command mode". This means Vim wants you to tell it what to do. Hit i and you'll go into insert mode. Now when you type it shows up on the screen.

I can stand for insert text and that may make it simpler for you to remember.

Now sometimes you may find yourself looking at a text file and for some reason you can get past a . in the text so when you start typing it's before the space you want it.

this is easy to get around, hit Escape, and then hit a and you'll be AFTER the cursor.

So far you've got i for insert text and a for after the cursor.

With me so far?


a = after cursor

i - insert

Now, how do you save text you've written? Well, you hit the Esc key, and type this:


:w

That will of course write the file. If you haven't given it a name yet and you want to save it as something hit the Escape jey again, and hit this:

:w yourfile.txt

Now, you don't have to call it a .txt of course. UNIx doesn't care if you make an extention or not, it just makes it easier for people coming from Windows where .txt means more than wasted space.

So what if you want to open a file on your computer and edit it? Well, you can do two things here:

vim filename

Which will open filename in vim. Remember though that if filename doesn't exist it will create it but not save it until you tell it save.

Or, you have Vim already open and don't want to quit, you can still open a file from inside Vim.

:e

That will open a file. You have to of course tell it which one you want opened, but it opens whatever you want it to.




Moving in Vim :




Say you're on an old old old machine and there are no arrow keys and moving the cursor looks impossible. Well, Unix has been made to work on anything, so as long as the keyboard is alright, Vim is as well.



To move right, make sure you hit escape to be sure you're in the command mode, and hit l (L) This moves right.

h will move you left.

k moves you up

j moves you down

The keys are next to each other on the keyboard so this isn't real hard to remember, it's just

l for the right

h for left

j for down

k for up



Now say you're done editing the file and want to save it. Well go back into command mode.


Now just type :w


This writes your file.


Now what if you want to save and quit Vim so you're back at the shell prompt?

:wq

That saves your text and quits Vim.

What if something was edited and it screwed up and I don't want to save??

Well, you may notice that :q isn't working because you have a text file you haven't yet written. Don't worry, just type this

:q!

That will tell Vim quit and it won't save the changes you made.