Yet Another Vi Tutorial


Vi text editor is powerful. As I started using it, I felt its advantage over others. The only problem is memorizing all these commands and shortcuts. In this tutorial, I not going to describe everything in detail, only some helpful commands (at least helpful to me), which I wanted to document first, for my own reference, and with no extra cost I am sharing this with you.

Two Modes

There are two modes:command mode and insert mode, you press mainly 'i' or 'a' to enter the insert mode, and ESC to go back to command mode.

Delete

While in command mode type: '[count]x' to delete 'count' letters starting from the position of the cursor. Without specifying any number and pressing just x will delete just one character under cursor.

Replace

If you want to replace a character in a word, say 'pen' into 'pin' then bring the cursor under this 'e' in 'pen' and press ri, so 'r' is the replace command, and 'i' is to replace 'e' in 'pen' to 'i' in 'pin'.

Undo

pressing u in command more will undo any changes. :redo command does redo.

Text Buffers: delete and paste

The command is "mdd, this means delete dd the line under cursor, and place it in buffer m, you can choose other character as buffer name. However, you do not need to choose a buffer and store your text in default buffer, thus you can just say dw and delete the word under cursor, and go where you want to paste it and type p which will paste the buffer after the cursor position, and P to paste it before the cursor.

Delete (or Cut) can be done with diffirent option like:

Instead of cutting text you can also copy or yank a text using y command with same options as d.

Searching

Searching can be done using / or ? commands followed by search string. / searches from the cursor position and below till the end of the file, and ? does the same but searches for expressions before the cursor. Here are various examples:

Moving the cursor


tutorial@textminingthequran.com