pf » Vi in a Nutshell
Vi in a Nutshell

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 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 /tmp/somefile
vi /tmp/somefile
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:
- Search
:/pattern- search for pattern in the file. This can be a regular expression. Hitnto go to the next match. - Find and Replace
:s/find/replace/g - Go to End of Line
$ - Beginning of Line
^ - Last line in the file
L - Middle of the file
M - Top of the file (Home) -
H - Go to line 10
:10 - Delete current line
dd - Copy or yank a line
Y- you can use5Yto copy 5 lines. Also tryyG, andy$. - Paste
p - Undo
u - Redo
Ctrl+R
Have any other handy vi tips? post them in the comments.
Related Entries
- Howto Backup your Mac incrementally over SSH - March 10, 2006
- 20 ways to Secure your Apache Configuration - December 6, 2005
- CSS Techniques Roundup - 20 CSS Tips and Tricks - September 22, 2005
- 4 Google Tricks - September 21, 2005
- Cheat Sheet Roundup - Over 30 Cheatsheets for developers - September 1, 2005
J/K: I'd love to use vi full time it just always seemed like a pain in the ass.
It came in handy in the days of Makefiles and also for checking shell scripts to make sure there were no spaces/tabs following a \ for line continuation.
dw -> delete word.
joe( Joe's Own Editor) fan here.
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 /tmp/somefile
vi /tmp/somefileVi 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.
Is there any way to turn this feature off?
One step further is to map another key to a sequence of keys. Use ":map z n." to make a press of the z key do the same as "n.". Now you can hold the z key down and FLY through your file. This is especially handy for lists.
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in









