vim - Basics

Vim is text editor built to create/modify text based files. It is quite powerful and customizable.

Vim can be used on mostly any Unix based computers and on Mac OS X.

Getting the vim on your computer

Alright, in case you skiped a few steps in this vim tutorial series, here is how you install vim on your computer

On a Debian base distribution, do the following.
# apt-get install vim
On ArchLinux based distibution, do the following.
# pacman -S vim

Cursor Movements

Most tutorial will tell you to use h, j, k, l to move the cursor. They are right, but it doesn't work in Insert mode. One other inconvenient is to remember that key does what.

I recommend you to use the arrow keys. They work in every mode and are quite intuitive

arrow-up    -- Moves the cursor up by one line
arrow-down  -- Moves the cursor down by one line
arrow-left  -- Moves the cursor left by one line
arrow-right -- Moves the cursor right by one line

The following shortcuts will allow you to the top and the bottom of the page

g, g (lowercase g twice) -- Moves the cursor to the top of the document
swift + G                -- Moves the cursor to the end of the document

Basic Editing

Editing a document can be quite scary the first few time, but you'll get good at it quickly. The key is to remember that you need to be in Insert mode, type what you need, press Esc and complete by saving your changes

i        -- Get into Insert mode (cursor stays where it is).
o        -- Creates a new line under the cursor, moves the cursor at the begining of said line.
esc      -- To leave the current mode (Insert, visual, ...)

Saving and Exiting

There is many way to save and quit a document.

:w       -- Saves the document
:q       -- Quit the document
:q!      -- Force the document to quit without saving any changes

Note: you can type :wq (or :qw) to save and quit the document in one command.

Cut, Copy, Paste

Alright, now that you know the basics here's how you can cut, copy and paste text in your document.

First move your cursor where your the text you want to cut/copy starts/ends. Enter in Visual mode by pressing v (Note: if your are in Insert mode you need to exit it first by pressing the Esc key).

Then use the arrows to select what you want to cut/copy. Use the c key to cut and the y key to copy (yank).

Then move the cursor where you want to paste the text. It will put the text on the right of your cursor.

v        -- visual mode
c        -- cut selected text
y        -- copy (yank) selected text
p        -- paste text in vim's memory (it pastes at the right of the cursor)

Bonus

d, d (double d) -- Deletes the current line
u               -- Undo
ctrl + r        -- Redo

Conclusion

You want to know more cool feature from vim have a look at my other vim tutorials.

Sources

  1. Vim Cheat Sheet
  2. A Great Vim Cheat Sheet
  3. Vim Commands Cheat Sheet
1