/[gentoo]/xml/htdocs/doc/en/vi-guide.xml
Gentoo

Diff of /xml/htdocs/doc/en/vi-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.11
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/vi-guide.xml,v 1.10 2003/12/30 15:23:55 aaby Exp $ --> 2<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/vi-guide.xml,v 1.11 2004/05/18 07:03:00 cam Exp $ -->
3<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> 3<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
4 4
5<guide link = "/doc/en/vi-guide.xml"> 5<guide link="/doc/en/vi-guide.xml">
6<title>Learning vi -- the "cheatsheet" technique</title> 6<title>Learning vi -- the "cheatsheet" technique</title>
7<author title="Author"> 7<author title="Author">
8 <mail link="drobbins@gentoo.org">Daniel Robbins</mail> 8 <mail link="drobbins@gentoo.org">Daniel Robbins</mail>
9</author> 9</author>
10<author title="Author"> 10<author title="Author">
18This guide will teach you how to use vi, using a cheat sheet method to 18This guide will teach you how to use vi, using a cheat sheet method to
19accelerate the learning process. This will be the first guide for vi, 19accelerate the learning process. This will be the first guide for vi,
20catering to beginners. 20catering to beginners.
21</abstract> 21</abstract>
22 22
23<version>1.1.3</version> 23<version>1.1.4</version>
24<date>December 30, 2003</date> 24<date>May 18, 2004</date>
25 25
26<chapter> 26<chapter>
27<title>Getting Started</title> 27<title>Getting Started</title>
28<section> 28<section>
29<title>Introduction</title> 29<title>Introduction</title>
30<body> 30<body>
31 31
32<p> 32<p>
33This tutorial will show you how to use vi, a powerful visual editor. 33This tutorial will show you how to use vi, a powerful visual editor.
34Using a special accelerated "cheat sheet" method, this tutorial is 34Using a special accelerated <e>cheat sheet</e> method, this tutorial is
35designed to make you a proficient vi user without requiring a huge 35designed to make you a proficient vi user without requiring a huge
36time commitment. In this vi tutorial, you'll learn how to move 36time commitment. In this vi tutorial, you'll learn how to move
37around, edit text, use insert mode, copy and paste text, and use 37around, edit text, use insert mode, copy and paste text, and use
38important vim extensions like visual mode and multi-window editing. 38important vim extensions like visual mode and multi-window editing.
39</p> 39</p>
41<p> 41<p>
42If you either don't know or aren't comfortable using vi, then you owe 42If you either don't know or aren't comfortable using vi, then you owe
43it to yourself to take this tutorial and get up to speed with one of 43it to yourself to take this tutorial and get up to speed with one of
44the most popular and powerful Linux/UNIX visual editing programs. 44the most popular and powerful Linux/UNIX visual editing programs.
45</p> 45</p>
46 46
47</body> 47</body>
48</section> 48</section>
49<section> 49<section>
50<title>About the guide</title> 50<title>About the guide</title>
51<body> 51<body>
59commands in a short period of time? 59commands in a short period of time?
60</p> 60</p>
61 61
62<p> 62<p>
63To tackle this challenge, as we proceed through this tutorial, we're 63To tackle this challenge, as we proceed through this tutorial, we're
64going to gradually put together a vi "cheat sheet". This sheet will 64going to gradually put together a vi cheat sheet. This sheet will
65contain all the important vi commands. After you've completed this 65contain all the important vi commands. After you've completed this
66tutorial, you'll be able to refer to this cheat sheet if you forget a 66tutorial, you'll be able to refer to this cheat sheet if you forget a
67particular command. Over time, as you memorize commands, you'll 67particular command. Over time, as you memorize commands, you'll
68gradually become less and less dependent on the cheat sheet. By using 68gradually become less and less dependent on the cheat sheet. By using
69the cheat-sheet technique, you'll be able to learn how to use vi 69the cheat-sheet technique, you'll be able to learn how to use vi
93<title>Introducing vim</title> 93<title>Introducing vim</title>
94<body> 94<body>
95 95
96<p> 96<p>
97There are many versions of vi, and I'm going to be showing you how to 97There are many versions of vi, and I'm going to be showing you how to
98use a version of vi called "vim". vim is very popular and has a 98use a version of vi called <c>vim</c>. vim is very popular and has a
99number of extensions that make vi a lot nicer (whenever I demonstrate 99number of extensions that make vi a lot nicer (whenever I demonstrate
100a vim-specific command, I'll make a note of it.) If you need to 100a vim-specific command, I'll make a note of it.) If you need to
101install vim, you can get it from <uri 101install vim, you can get it from <uri
102link="http://www.vim.org/">www.vim.org</uri>. In addition to an 102link="http://www.vim.org/">www.vim.org</uri>. In addition to an
103enhanced command-line vi, vim also comes with gvim, a nice graphical 103enhanced command-line vi, vim also comes with <c>gvim</c>, a nice graphical
104editor which can be configured to use the excellent GTK+ gui library. 104editor which can be configured to use the excellent GTK+ gui library.
105Here's a gvim screenshot from my system: 105Here's a gvim screenshot from my system:
106</p> 106</p>
107 107
108<figure link="http://www.ibiblio.org/web-gentoo/images/vishot.png" 108<figure link="http://www.ibiblio.org/web-gentoo/images/vishot.png"
129to take a look at many of them. For this part of the tutorial, find 129to take a look at many of them. For this part of the tutorial, find
130an unimportant text file and load it into vi by typing: 130an unimportant text file and load it into vi by typing:
131</p> 131</p>
132 132
133<pre caption="Loading a file into vi"> 133<pre caption="Loading a file into vi">
134$ vi myfile.txt 134$ <i>vi myfile.txt</i>
135</pre> 135</pre>
136 136
137<p> 137<p>
138If you have vim installed, type "vim myfile.txt". If you'd prefer to 138If you have vim installed, type <c>vim myfile.txt</c>. If you'd prefer to
139use gvim, type "gvim myfile.txt". myfile.txt should be the name of a 139use gvim, type <c>gvim myfile.txt</c>. <path>myfile.txt</path> should be the name of a
140text file on your system. 140text file on your system.
141</p> 141</p>
142 142
143</body> 143</body>
144</section> 144</section>
147<body> 147<body>
148 148
149<p> 149<p>
150After vi loads, you should see a part of the text file you loaded 150After vi loads, you should see a part of the text file you loaded
151on your screen. Congratulations -- you're in vi! Unlike many 151on your screen. Congratulations -- you're in vi! Unlike many
152editors, when vi starts up, it is in a special mode called "command 152editors, when vi starts up, it is in a special mode called <e>command
153mode". This means that if you press "l" on the keyboard, instead of 153mode</e>. This means that if you press <c>l</c>on the keyboard, instead of
154inserting an "l" into the file at the current cursor position, the 154inserting an <c>l</c> into the file at the current cursor position, the
155cursor will move one character to the right instead. In command mode, 155cursor will move one character to the right instead. In command mode,
156the characters on your keyboard are used to send commands to vi rather 156the characters on your keyboard are used to send commands to vi rather
157than insert literal characters into the text. One of the most 157than insert literal characters into the text. One of the most
158essential types of commands are movement commands; let's take a look 158essential types of commands are movement commands; let's take a look
159at some. 159at some.
202</p> 202</p>
203 203
204<p> 204<p>
205You can also use <c>&lt;CTR&gt;F</c> and <c>&lt;CTR&gt;B</c> to move 205You can also use <c>&lt;CTR&gt;F</c> and <c>&lt;CTR&gt;B</c> to move
206forwards and backwards a page at a time. Modern versions of vi (like 206forwards and backwards a page at a time. Modern versions of vi (like
207vim) will also allow you to use the PGUP and PGDOWN keys for this 207vim) will also allow you to use the <c>PGUP</c> and <c>PGDOWN</c> keys for this
208purpose. 208purpose.
209</p> 209</p>
210 210
211</body> 211</body>
212</section> 212</section>
228<title>Word moves, part 2</title> 228<title>Word moves, part 2</title>
229<body> 229<body>
230 230
231<p> 231<p>
232After playing around with the word movement commands, you may have 232After playing around with the word movement commands, you may have
233noticed that vi considers words like "foo-bar-oni" as five separate 233noticed that vi considers words like <c>foo-bar-oni</c> as five separate
234words! This is because by default, vi delimits words by spaces 234words! This is because by default, vi delimits words by spaces
235<e>or</e> punctuation. foo-bar-oni is therefore considered five 235<e>or</e> punctuation. <c>foo-bar-oni</c> is therefore considered five
236words: "foo","-","bar","-" and "oni". 236words: <c>foo</c>, <c>-</c>, <c>bar</c>, <c>-</c> and <c>oni</c>.
237</p> 237</p>
238 238
239<p> 239<p>
240Sometimes, this is what you want, and sometimes it isn't. 240Sometimes, this is what you want, and sometimes it isn't.
241Fortunately, vi also understands the concept of a "bigword". vi 241Fortunately, vi also understands the concept of a "bigword". vi
242delimits bigwords by <e>spaces or newlines only</e>. This means that 242delimits bigwords by <e>spaces or newlines only</e>. This means that
243while foo-bar-oni is considered five vi words, it's considered only 243while <c>foo-bar-oni</c> is considered five vi words, it's considered only
244one vi bigword. 244one vi bigword.
245</p> 245</p>
246 246
247</body> 247</body>
248</section> 248</section>
280</chapter> 280</chapter>
281 281
282<chapter> 282<chapter>
283<title>Quitting</title> 283<title>Quitting</title>
284<section> 284<section>
285<title>Quitting</title>
286<body> 285<body>
287 286
288<p> 287<p>
289We've covered the basic movement commands, but there are another 288We've covered the basic movement commands, but there are another
290couple of commands that you need to know. Typing <c>:q</c> will quit 289couple of commands that you need to know. Typing <c>:q</c> will quit
292file in some way. To tell vi to quit, throwing away any changes, type 291file in some way. To tell vi to quit, throwing away any changes, type
293<c>:q!</c>. You should now be at the command prompt. 292<c>:q!</c>. You should now be at the command prompt.
294</p> 293</p>
295 294
296<p> 295<p>
297In vi, any command that begins with a ":" is said to be an 296In vi, any command that begins with a <c>:</c> is said to be an
298<e>ex-mode</e> command. This is because vi has a built-in non-visual 297<e>ex-mode</e> command. This is because vi has a built-in non-visual
299editor called <e>ex</e>. It can be used similarly to sed to perform 298editor called <e>ex</e>. It can be used similarly to sed to perform
300line-based editing operations. In addition, it can also be used to 299line-based editing operations. In addition, it can also be used to
301quit, as we've just seen. If you ever hit the <c>Q</c> key while in 300quit, as we've just seen. If you ever hit the <c>Q</c> key while in
302command mode, you'll be transported to ex mode. If this ever happens 301command mode, you'll be transported to ex mode. If this ever happens
379</p> 378</p>
380 379
381<p> 380<p>
382In vim (and other advanced vi editors, like elvis)<c>:w</c>, you can 381In vim (and other advanced vi editors, like elvis)<c>:w</c>, you can
383have multiple buffers open at once. To open a file into a new window, 382have multiple buffers open at once. To open a file into a new window,
384type <c>:sp filename.txt</c>. <e>filename.txt</e> will appear open 383type <c>:sp filename.txt</c>. <path>filename.txt</path> will appear open
385for editing in a new split window. To switch between windows, type 384for editing in a new split window. To switch between windows, type
386<c>&lt;CTR&gt;w&lt;CTR&gt;w</c> (control-w twice). Any <c>:q</c>, 385<c>&lt;CTR&gt;w&lt;CTR&gt;w</c> (control-w twice). Any <c>:q</c>,
387<c>:q!</c>, <c>:w</c> and <c>:x</c> commands that you enter will only 386<c>:q!</c>, <c>:w</c> and <c>:x</c> commands that you enter will only
388be applied to the currently-active window. 387be applied to the currently-active window.
389</p> 388</p>
394<title>Simple edits</title> 393<title>Simple edits</title>
395<body> 394<body>
396 395
397<p> 396<p>
398Now, it's time to start learning some of the simple editing commands. 397Now, it's time to start learning some of the simple editing commands.
399The commands that we'll cover here are considered "simple" because the 398The commands that we'll cover here are considered <e>simple</e> because the
400commands keep you in command mode. The more complex editing commands 399commands keep you in command mode. The more complex editing commands
401automatically put you into insert mode -- a mode that allows you to 400automatically put you into insert mode -- a mode that allows you to
402enter literal data from the keyboard. We'll cover those in a bit. 401enter literal data from the keyboard. We'll cover those in a bit.
403</p> 402</p>
404 403
485become comfortable with insert mode, its complexity (and flexibility) 484become comfortable with insert mode, its complexity (and flexibility)
486will become an asset. 485will become an asset.
487</p> 486</p>
488 487
489<p> 488<p>
490In vi insert mode, you'll be able to enter text directly to the screen 489In vi <e>insert mode</e>, you'll be able to enter text directly to the screen
491just like you can in many other visual editors. Once you've entered 490just like you can in many other visual editors. Once you've entered
492your modifications, you can hit escape to return to command mode. You 491your modifications, you can hit escape to return to <e>command mode</e>. You
493can enter insert mode by pressing <c>i</c> or <c>a</c>. If you press 492can enter insert mode by pressing <c>i</c> or <c>a</c>. If you press
494<c>i</c>, your text will be <e>inserted</e> before the current 493<c>i</c>, your text will be <e>inserted</e> before the current
495character, and if you hit <c>a</c>, your text will be <e>appended</e> 494character, and if you hit <c>a</c>, your text will be <e>appended</e>
496after the current character. Remember, after you enter your text, hit 495after the current character. Remember, after you enter your text, hit
497<c>&lt;ESC&gt;</c> to return to command mode. 496<c>&lt;ESC&gt;</c> to return to command mode.
509to command mode. After hitting <c>a</c> or <c>i</c>, try hitting 508to command mode. After hitting <c>a</c> or <c>i</c>, try hitting
510<c>&lt;ENTER&gt;</c>, and see what happens. Try using the arrow keys 509<c>&lt;ENTER&gt;</c>, and see what happens. Try using the arrow keys
511and the <c>&lt;DEL&gt;</c> key to get a feel for how insert mode 510and the <c>&lt;DEL&gt;</c> key to get a feel for how insert mode
512works. By using the arrow keys and <c>&lt;DEL&gt;</c> key, you can 511works. By using the arrow keys and <c>&lt;DEL&gt;</c> key, you can
513perform significant editing steps without repeatedly entering and 512perform significant editing steps without repeatedly entering and
514leaving insert mode 513leaving insert mode.
515</p> 514</p>
516 515
517</body> 516</body>
518</section> 517</section>
519<section> 518<section>
626<section> 625<section>
627<title>Visual mode</title> 626<title>Visual mode</title>
628<body> 627<body>
629 628
630<p> 629<p>
631The best way to cut and paste is to use visual mode, a special mode that 630The best way to cut and paste is to use <e>visual mode</e>, a special mode that
632has been added to modern versions of vi, like vim and elvis. You can think 631has been added to modern versions of vi, like vim and elvis. You can think
633of visual mode as a "highlight text" mode. Once the text is highlighted, 632of visual mode as a "highlight text" mode. Once the text is highlighted,
634it can be copied or deleted, and then pasted. If you are using gvim, you 633it can be copied or deleted, and then pasted. If you are using gvim, you
635can highlight by simply dragging the left mouse button over a particular 634can highlight by simply dragging the left mouse button over a particular
636region: 635region:
719compose emails. Refer to the cheat sheet when needed; you'll find 718compose emails. Refer to the cheat sheet when needed; you'll find
720that within the week, you'll have nearly all the commands memorized 719that within the week, you'll have nearly all the commands memorized
721and your vi productivity will shoot through the roof! 720and your vi productivity will shoot through the roof!
722</p> 721</p>
723 722
723<p>
724If you want to use vi as your default editor make the following change
725to <path>/etc/rc.conf</path>:
726</p>
727
728<pre caption="Setting vi as the default editor">
729<comment>(Set EDITOR to your preferred editor.)</comment>
730#EDITOR="/bin/nano"
731EDITOR="/usr/bin/vim"
732#EDITOR="/usr/bin/emacs"
733</pre>
734
724</body> 735</body>
725</section> 736</section>
726<section> 737<section>
727<title>Resources</title> 738<title>Resources</title>
728<body> 739<body>
732more about vi: 743more about vi:
733</p> 744</p>
734 745
735<ul> 746<ul>
736 <li> 747 <li>
737 <uri link="http://www.thomer.com/thomer/vi/vi.html">The vi Lovers 748 <uri link="http://www.thomer.com/thomer/vi/vi.html">The vi Lovers
738 Home Page</uri>, an excellent resource for all things vi 749 Home Page</uri>, an excellent resource for all things vi
739 </li> 750 </li>
740 <li> 751 <li>
741 <uri link="http://www.vim.org/">The vim homepage</uri> is the place 752 <uri link="http://www.vim.org/">The vim homepage</uri> is the place
742 to go for all your vim needs 753 to go for all your vim needs

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.20