Vi in a Nutshell
By Pete Freitag
The unix text editor
vi probably has more features than Microsoft Word yet I've only been using about 5 of them. Recently I've been learning a bit more about it. I now know some of the more handy features thanks to the VI reference in forth edition of Unix in a Nutshell (ISBN 0596100299) which was just released in October.
The reason I think
vi is an important editor to learn is that it is typically installed on any unix system (including Mac OSX) by default. Other unix text editors such as emacs aren't installed by default as often.
Basic VI features (beginners only)
Using vi is pretty easy if you know a few things about it, if you don't you probably won't even be able to edit or save a file. Lets start by editing a file
Vi starts up in command mode, you can give VI commands to run such as delete this line, search for this, etc.
To start we want to give the insert command so hit
i, you should see
-- INSERT -- at the bottom of the screen. Go ahead and write a haiku or something.
Now to save it you need to go back into command mode this is done by hitting
ESC now type
wq (this means write and quit).
Ok that's the basics you can get pretty far just knowing that.
Handy Features in VI
Here's a list of some of the commands that I have found to be quite handy:
:/pattern- search for pattern in the file. This can be a regular expression. Hit
nto go to the next match.
- Find and Replace
- Go to End of Line
- Beginning of Line
- Last line in the file
- Middle of the file
- Top of the file (Home) -
- Go to line 10
- Delete current line
- Copy or yank a line
Y- you can use
5Yto copy 5 lines. Also try
Have any other handy vi tips? post them in the comments.
Vi in a Nutshell was first published on December 01, 2005.
If you like reading about unix, vi, nutshell, reference, tips, or tricks then you might also like:
- Howto Backup your Mac incrementally over SSH
- 20 ways to Secure your Apache Configuration
- CSS Techniques Roundup - 20 CSS Tips and Tricks
- 4 Google Tricks
Weekly Security Advisories Email
Advisory Week is a new weekly email containing security advisories published by major software vendors (Adobe, Apple, Microsoft, etc).