<p>Let's continue our rapid command-covering pace. In command-mode, you can jump to a particularline by typing <c>G</c>. To jump to the first line of a file, type <c>1G</c>. Note that <c>G</c> is capitalized.</p>

241

<p>If you want to jump to the next occurence of a particular text pattern, type <c>/&lt;regexp&gt;</c> and hit <c>enter</c>. Replace

242

&lt;regexp&gt; with the regular expression you're looking for. If you don't know how to use regular expressions, don't

243

fret -- typing <c>/foo</c> will move to the next occurence of <i>foo</i>. The only thing you'll need to watch out for is when

244

you want to refer to the literal <i>^</i>, <i>.</i>, <i>$</i> or <i>\</i> characters. Prefix these characters with a backslash (<i>\</i>), and you'll

245

be set. For example, <c>/foo\.gif</c> will search for the next occurence of "<i>foo.gif</i>".</p>

commands out in your very own vi editor. You can also type <c>//</c> to repeat the last search.</p>

248

249

</body>

250

</section>

251

</chapter>

252

<chapter>

253

<title>Saving and Editing</title>

254

<section>

255

<title>Save and save as...</title>

256

<body>

257

<p>We've covered how you can use the <i>ex</i> command <c>:q</c> to quit from vi. If you want to save your

258

changes, type <c>:w</c>. If you want to save your changes to another file, type <c>:w filename.txt</c> to

259

save as <e>filename.txt</e>. If you want to save and quit, type <c>:x</c> or <c>:wq</c>.</p>

260

<p>In vim (and other advanced vi editors, like elvis)<c>:w</c>, you can have multiple buffers open at once. To open a file into a new window, type <c>:sp filename.txt</c>. <e>filename.txt</e> will appear open for editing in a new split window. To switch between windows, type <c>&lt;CTR&gt;w&lt;CTR&gt;w</c> (control-w twice). Any <c>:q</c>, <c>:q!</c>, <c>:w</c> and <c>:x</c> commands that you enter will only be applied to the currently-active window.</p>

261

</body>

262

</section>

263

264

<section>

265

<title>Simple edits</title>

266

<body>

267

<p>Now, it's time to start learning some of the simple editing commands. The commands that

268

we'll cover here are considered "simple" because the commands keep you in command mode. The

269

more complex editing commands automatically put you into insert mode -- a mode that allows

270

you to enter literal data from the keyboard. We'll cover those in a bit.</p>

271

<p>For now, try moving over some characters and hitting <c>x</c> repeatedly. You'll see that <c>x</c>

272

will delete the current character under the cursor. Now, move to the middle of the paragraph

273

somewhere in your text file, and hit <c>J</c> (capitalized). You'll see that the <c>J</c> command tells

274

vi to join the previous line to the end of the current line. Now, move over a character and hit

275

<c>r</c>, and then type in a new character; you'll see that the original character has been replaced.

276

Finally, move to any line in the file and

277

type <c>dd</c>. You'll see that <c>dd</c> deletes the current line of text.</p>

278

279

</body>

280

</section>

281

<section>

282

<title>Repeating and deleting</title>

283

<body>

284

<p>You can repeat any editing command by hitting the <c>.</c> key. If you experiment, you'll see that

285

typing <c>dd...</c> will delete 4 lines, and <c>J......</c> will join four lines. As usual, vi provides with

286

another handy shortcut.

287

</p>

288

<p>To delete text, you can also use the <c>d</c> command combined with any movement command. For example,

289

<c>dw</c> will delete from the current position to the beginning of the next word; <c>d)</c> will delete up until the

290

end of the next sentence, and <c>d}</c> will delete the remainder of the paragraph. Experiment with the

291

<c>d</c> command and the otehr editing commands until you're comfortable with them.</p>

292

</body>

293

</section>

294

<section>

295

<title>Undo!</title>

296

<body>

297

<p>Now that we're experimenting with deletion, it would be a good time to learn how to undo any changes.

298

By pressing <c>u</c>, the original version of vi allowed you to undo the last edit only. However, modern versions

299

of vi like vim will allow you to repeatedly press <c>u</c> to continue to undo changes to your file. Try combining

300

some <c>d</c> and <c>u</c> commands together.

301

</p>

302

</body>

303

</section>

304

305

<section>

306

<title>Updating the cheat sheet</title>

307

<body>

308

<p>Time to update the cheat sheet! After adding all the commands we've covered so far, your

<li><urilink="http://www.vim.org">The vim homepage</uri> is the place to go for all your vim needs.</li>

497

<li>If you're looking for a good, old-fashioned book, <urilink="http://www.oreilly.com/catalog/vi6/">Learning the vi Editor, 6th Edition</uri> would be an excellent choice. Contains good coverage of vi and vi clones.</li>