-
Notifications
You must be signed in to change notification settings - Fork 0
/
vi.html
283 lines (283 loc) · 11.6 KB
/
vi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!doctype html><html>
<head>
<link rel="STYLESHEET" href="main.css" type="text/css">
<title>The vi Editor - A quick reference guide. | SS64.com</title>
<meta NAME="Description" CONTENT="A quick one page guide to using vi, the default UNIX text editor.">
<meta charset="UTF-8">
<style type="text/css">
.grn {color: #006633;}
.code {font-size :120%; margin-botton: 0px;}
.label { text-align: right;}
table {width: 80%; padding: 0; border-collapse: collapse;}
tr, td {font-family: verdana, helvetica,Arial,Sans-Serif; font-weight: normal; font-size: 100%;vertical-align: text-top; border: 1px solid grey; padding: 4px; border-spacing: 0; }
.code1 {font-size :120%;}
</style>
</head><body><h1>The vi editor (<b>vi</b>sual editor) - A quick reference guide.</h1>
<p><b>To startup vi:</b></p>
<p> <span class="code">vi <i>filename</i></span><br>
<br>
<b>Insert text </b>(Insert mode)<b>:</b></p>
<p>Vi has two modes <i>insert</i> mode and <i>command</i> mode. The editor begins in command mode, where cursor movement and copy/paste commands can be issued.</p>
<table>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Open line ab<u>o</u>ve cursor </div></td>
<td class="code">O</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div class="label"><u>I</u>nsert text at beginning of line</div></td>
<td class="code">I </td>
<td><div class="label"><u>I</u>nsert text at cursor</div></td>
<td class="code">i</td>
<td><div class="label"><u>a</u>ppend text after cursor</div></td>
<td class="code">a</td>
<td><div class="label"><u>A</u>ppend text at line end</div></td>
<td class="code">A</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Open line bel<u>o</u>w cursor</div></td>
<td class="code">o</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p><b>Switch to Command mode:</b></p>
<blockquote>
<p><span class="label">Switch to command mode:</span> <span class="code">[ESC]</span></p>
<p>Most commands execute as soon as typed except for "colon" commands which execute when you press the return key. </p>
</blockquote>
<p><b>Cursor Movement</b> (command mode):</p>
<table>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Scroll <u>B</u>ackward 1 screen</div></td>
<td class="code">[ctrl] b</td>
<td> </td>
<td></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Scroll <u>U</u>p 1/2 screen</div></td>
<td class="code">[ctrl] u</td>
<td> </td>
<td></td>
</tr>
<tr>
<td><div class="label">Go to beginning of line</div></td>
<td class="code">0</td>
<td><div class="label">Go to line <span class="grn"><var>n</var></span></div></td>
<td><var class="grn">n</var><span class="code">G</span></td>
<td><div class="label">Go to end of line</div></td>
<td><div class="code">$</div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Scroll <u>D</u>own 1/2 screen</div></td>
<td class="code">[ctrl] d</td>
<td><div class="label">Go to line number <span class="grn">##</span></div></td>
<td><div class="code">:<span class="grn">##</span></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Scroll <u>F</u>orward 1 screen</div></td>
<td class="code">[ctrl] f</td>
<td> </td>
<td></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Go to last line</div></td>
<td class="code">G</td>
<td> </td>
<td></td>
</tr>
<tr>
<td><div class="label">Scroll by sentence <abbr title="Forward/Back">f/b</abbr></div></td>
<td class="code">( )</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
</tr>
<tr>
<td><div class="label">Scroll by word <abbr title="Forward/Back">f/b</abbr></div></td>
<td class="code">w b</td>
<td><div class="label">Move left, down, up, right</div></td>
<td class="code"><abbr title="The four keys HJKL in a line make it possible to keep one finger on each and move about as quickly as possible">h j k l</abbr></td>
<td><div class="label">Left <span class="grn">6</span> chars</div></td>
<td><div class="code"><span class="grn">6</span>h</div></td>
</tr>
<tr>
<td><div class="label">Scroll by paragraph <abbr title="Forward/Back">f/b</abbr></div></td>
<td class="code">{ } </td>
<td><div class="label">Move left, down, up, right</div></td>
<td class="code">← <span class="code1">↓ </span><span class="code1">↑ </span> →<span class="code1"> Arrow Keys</span></td>
<td><div class="label">Go to line #<span class="grn">6</span></div></td>
<td><div class="code"><span class="grn">6</span>G</div></td>
</tr>
</table>
<p><b>Delete text</b> (command mode):</p>
<table>
<tr>
<td><div class="label">Change word </div></td>
<td class="code">cw</td>
<td><div class="label">Replace one character</div></td>
<td class="code">r</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div class="label">Delete word</div></td>
<td class="code">dw</td>
<td><div class="label">Delete text at cursor</div></td>
<td class="code">x</td>
<td><div class="label">Delete entire line (to buffer)</div></td>
<td class="code">dd</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Delete (backspace) text at cursor</div></td>
<td class="code">X</td>
<td><div class="label">Delete <span class="grn">5</span> lines (to buffer)</div></td>
<td class="code"><span class="grn">5</span>dd</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div class="label">Delete current to end of line</div></td>
<td class="code">D</td>
<td><div class="label">Delete lines <span class="grn">5-10</span></div></td>
<td class="code">:<span class="grn">5,10</span>d </td>
</tr>
</table>
<p><b>Editing</b> (command mode):</p>
<table>
<tr>
<td><div class="label">Copy line</div></td>
<td class="code">yy </td>
<td><div class="label">Copy <var class="grn">n</var> lines</div></td>
<td class="code"><var class="grn">n</var>yy</td>
<td><div class="label">Copy lines <span class="grn">1-2 </span>/paste after <span class="grn">3</span></div></td>
<td class="code">:<span class="grn">1,2</span>t<span class="grn">3</span></td>
</tr>
<tr>
<td><div class="label">Paste above current line</div></td>
<td class="code">P</td>
<td><div> </div></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div class="label">Paste below current line</div></td>
<td class="code">p</td>
<td> </td>
<td> </td>
<td><div class="label">Move lines <span class="grn">4-5 </span>/paste after <span class="grn">6</span></div></td>
<td class="code">:<span class="grn">4,5</span>m<span class="grn">6</span></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><div class="label">Join previous line</div></td>
<td class="code">J</td>
</tr>
<tr>
<td><div class="label">Search backward for <var>string</var></div></td>
<td class="code">?<var>string</var></td>
<td><div class="label">Search forward for <var>string</var></div></td>
<td class="code">/<var>string</var></td>
<td><div class="label">Find next <var>string</var> occurrence</div></td>
<td class="code">n</td>
</tr>
<tr>
<td><div class="label">% (entire file)<b> s </b>(search and replace) /old text with new/ <b>c</b> (confirm) <b>g</b> (global - all)</div></td>
<td class="code"><b>:%s/</b>oldstring<b>/</b>newstring<b>/cg</b></td>
<td> </td>
<td> </td>
<td><div class="label">Ignore case during search</div></td>
<td class="code">:set ic</td>
</tr>
<tr>
<td><div class="label">Repeat last command</div></td>
<td><b class="code">.</b></td>
<td><div class="label">Undo previous command</div></td>
<td class="code">u</td>
<td><div class="label">Undo all changes to line</div></td>
<td class="code">U</td>
</tr>
</table>
<p><b>Save and Quit</b> (command mode):</p>
<table>
<tr>
<td><div class="label">Save changes to buffer</div></td>
<td><div class="code">
<div class="code">:w</div>
</div></td>
<td><div class="label">Save changes and quit vi</div></td>
<td><div class="code">ZZ or :wq</div></td>
<td><div class="label">Save file to new file</div></td>
<td><div class="code">
<div class="code">:w <i>file</i></div>
</div></td>
</tr>
<tr>
<td> </td>
<td></td>
<td><div class="label">Quit without saving</div></td>
<td><div class="code">
<div class="code">:q!</div>
</div></td>
<td><div class="label">Save lines to new file</div></td>
<td><div class="code">
<div class="code">:<span class="grn">10,15</span>w <i>file</i></div>
</div></td>
</tr>
</table>
<p>In general a number <span class="code"><i>n</i></span> preceding any vi command will tell vi to repeat
that command <span class="code"><i>n</i></span> times.</p>
<p><span class="code">:syntax on</span> Turn on syntax highlighting<br>
<span class="code">:syntax off </span>Turn off syntax highlighting<br>
<span class="code">:set number</span> Turn on Line numbering (shorthand :set nu) <br>
<span class="code">:set nonumber</span> Turn off Line numbering (shorthand :set nonu) </p>
<p><span class="code">:set ignorecase</span> Ignore case sensitivity when searching<br>
<span class="code">:set noignorecase</span> Restore case sensitivity (default) <br>
<br>
<span class="code">:set autoindent </span>Turn on Auto-indentation <br>
Use the command<span class="code"> >></span> to indent and the <span class="code"><<</span> command to outdent <br>
<span class="code">:set shiftwidth=4</span> Set indentation to four spaces<br>
<span class="code">:set noautoindent</span> Turn off Auto-indentation<br>
Change all Windows CR/LF to Unix style LF line endings in the current file:<br>
<span class="code">:g/^M/s///g<br>
</span>(To enter the <span class="code">^M</span>, type CTRL-V CTRL-M)</p>
<p> The vi editor was an update on the earlier <span class="code">ex</span> (and <span class="code">ed</span>) editors, it introduced a <i>Visual Interactive</i> mode which was contracted to give the name <span class="code">vi</span>.</p>
<p class="quote"><i>“vi was written for a world that doesn't exist anymore - unless you decide to get a satellite phone and use it to connect to the Net at 2400 baud” - <a href="http://www.theregister.co.uk/Print/2003/09/11/bill_joys_greatest_gift/">Bill Joy</a></i></p>
<p><b>Related:</b></p>
<p><a href="vi-reference.html">Full list of VI commands</a> <br>
<a href="http://michael.peopleofhonoronly.com/vim/">Programmers Vim cheat sheet</a><br>
<a href="http://www.openvim.com/tutorial.html">VIM tutor</a><br>
<a href="https://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118">How to grok vi</a> - Stack Overflow<br>
<a href="http://happyedit.se/">HappyEdit</a> - The modern Vim-inspired text editor<br>
<a href="http://vim.spf13.com/">vim.spf13</a> - The Ultimate Vim Distribution<br>
<a href="https://github.com/grantm/bcvi">bcvi</a> - Back Channel vi - remote file editing with SSH<br>
<a href="https://www.amazon.com/exec/obidos/ASIN/1680501275/ss64">book - Practical vim</a> by Drew Neil <br>
<a href="https://www.amazon.com/exec/obidos/ASIN/059652983X/ss64">book - Learning the vi & vim Editor</a><br>
<a href="http://code.google.com/p/macvim/">MacVim</a> & <a href="http://jeffkreeftmeijer.com/2011/vim-is-hard-i-just-want-to-click-around/">MacVim vs TextMate</a> </p> | update</body>
</html>