Tip of the Week 2005-09-26
From FedoraNEWS.ORG
Welcome to Tip of the Week!
Tip of the Week releases on every monday with Fedora Weekly News.
Tip of the week: Tips for using vi/vim
- submitted by Tejas Dinkar
Here is a quick guide on using vi. This will be VERY usefull if you are working on an old machine, want to edit a file really quickly, or just dislinke fancy, complicated GUIs.
Well, to start off, open a terminal, and type:
$ vi <file>
Here, <file> can be a new, or already present file
There are 3 modes in vi(m).
- Command Mode - This is the mode which you start in. You start in this mode
- Insert / Replace Mode - As the name suggests, if you are in Insert or replace mode, and you type character, then you will be typing into the document. In vim it will say '-- INSERT --' at the bottom of the screen if you are in this mode
- ex mode - This is where you do the saving of the file, and others
At any given time, if you are not sure what you are doing, keep pressing <esc> until you are back in the command mode
Now, say you are at command mode (ex: you just opened vi). This is the Best place to move the cursor. Appart from the arrow keys, you can also use the following:
- w / b - jump to next Word / previous word
- ) / ( - jump to next sentence / previous sentence
- } / { - jump to next paragraph / previous paragraph
Align, the cursor to where you want to edit, and then press one of the following to start editing (remember, vi is case sensitive, so you may need to press shift)
- i - Start inserting at the given point (before cursor)
- a - Start inserting after the given point
- R - Replace mode.
- O/o - Open a new line above/below the current line, and start insert
After you are in the appropriate mode, you can start typing and editing the document.
Pess <esc> to come back to command mode when you are done
At the command mode, press ':' to enter the ex mode. This is where commands can be typed. When you are in ex mode, you will see a ':' at the bottom of the screen. You type in thecommand, and then press enter. Here are a few commands:
- w - write to the current file
- w <file> - save to a different file
- q - quit
- q! - quit even if document is not saved
- wq - write and quit
In the command mode, there are also a couple of time saving tips. Memorise these:
- d - delete
- c - change
- y - yank (copy)
- p - put (paste)
If you press p, whatever was there on the 'clipboard' is pasted below the current line
if the letter repeats twice, it applies to the current line. Ex:
- dd deletes the current line
- cc changes the current line
- yy copies the current line to the 'clipboard'
you can also couple it with the various keys to move the cursor. ex:
- d} deletes the rest of the paragraph
- y( copies from the beginning of the sentence
If you type a number in the beginning, you can make even multiply the effect:
- 5dd - delete the next 5 lines
- 2y} - yank the next two pargraphs
And one last thing:
pressing u undoes the last change
pressing U undoes all recent changes to the line you are in
pressing ctrl-r redoes the change
Previous Tips of the Week Can be found Here: Tips of the IceBurg
Add a Tip
If you have a tip you want to add, contact Tejas Dinkar (mailto:tejasdinkar@gmail.com).

