This page (revision-33) was last changed on 21-Jan-2018 01:53 by BlakeMcBride

This page was created on 18-Sep-2012 15:31 by BlakeMcBride

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
33 21-Jan-2018 01:53 8 KB BlakeMcBride to previous
32 18-Jan-2018 21:25 8 KB BlakeMcBride to previous | to last
31 25-Dec-2017 21:00 8 KB BlakeMcBride to previous | to last
30 17-May-2017 12:23 8 KB BlakeMcBride to previous | to last
29 17-May-2017 12:22 8 KB BlakeMcBride to previous | to last
28 17-May-2017 12:21 8 KB BlakeMcBride to previous | to last
27 05-Apr-2017 15:02 8 KB BlakeMcBride to previous | to last
26 20-Apr-2016 10:22 8 KB BlakeMcBride to previous | to last
25 06-Oct-2014 18:15 8 KB BlakeMcBride to previous | to last
24 26-Jan-2014 21:32 7 KB BlakeMcBride to previous | to last
23 28-Nov-2013 12:59 7 KB BlakeMcBride to previous | to last
22 28-Nov-2013 12:50 7 KB BlakeMcBride to previous | to last
21 28-Nov-2013 12:46 7 KB BlakeMcBride to previous | to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

1!!!VI Editor
2
3The VI editor has three main modes:
4VI is the standard visual text editor available on all Unix, Linux, BSD, and other Unix-like computer systems. It also comes with Mac OS/X, and is available for Windows.
5
6The VI editor has three modes:
7
8* command mode
9* edit mode (insert or overtype text)
10* edit mode (insert or over-type text)
11* ex mode
12
13When you first enter VI you are in command mode.
14
15Edit mode is used to insert or overwrite new text. Command mode is
16used for almost everything else. Knowing which mode you are in at any
17point is critical. You can always hit the Esc key to go from edit
18mode to command mode. Hitting Esc when you are in command mode does
19nothing so if you are confused just hit the Esc key and you'll know
20nothing. So if you are confused, just hit the Esc key and you'll know
21you are in command mode.
22
23__Edit mode__ -> __command mode__ = Esc
24
25__Command mode__ -> __ex mode__ = :
26
27Commands can be proceeded with a number. This causes that command to
28be executed the specified number of times. For example 5dd will
29delete 5 lines.
30
31^ means control, so ^f means control-f
32
33Commands are case sensitive so that j and J are different commands.
34
35!!Commands (run from command mode)
36
37!!Saving, exiting, and file commands
38
39|ZZ|save and quit
40|:q|quit without saving (only works of file had not been edited)
41|:q!|quit without saving (even if file had been changed - lose changes)
42|:w|write (save) file but don't quit
43|:w newname|write (save) file to new file named newname
44|:wq|write (save) and quit
45|:r filename|read (insert) file filename into the current buffer after the current line
46
47!!Cursor movement
48!!Cursor movement (in addition to possible cursor keys)
49
50(The letters hjkl on the keyboard form a sort of arrow keys)\\
51(The letters hjkl on the keyboard form a set of arrow keys)\\
52|h| left one character
53|j| down one character
54|k| up one character
55|l| right one character
56
57See Searching below.
58
59|return|first character of next line
60|+|first character of next line
61|-|first character on previous line
62|w| word right
63|b| back a word
64|0| beginning of line
65|0| beginning of line (zero)
66|$| end of line
67|G| goto end-of-file
68|1G| goto beginning of file
69|15G| goto line 15 (basically you can preced G with any line number)
70|15G| goto line 15 (basically you can precede G with any line number)
71|H|home - top of screen
72|M|middle of screen
73|L|last line on screen
74
75!!Screen movement (scrolling)
76
77|^f| forward a page
78|^b| back a page
79|z return|scroll current line to top-of-screen
80|z.|scroll current line to middle-of-screen
81|z-|scroll current line to bottom-of-screen
82
83
84!!Text editing (all text entry except r ends by hitting the Esc key)
85!!Text editing (Edit Mode - all text entry except "r" ends by hitting the Esc key)
86
87|i| inserting text starting before the cursor position
88|a| append text after the cursor position
89|r| replace a single character
90|R| replace or over-type (doesn't require Esc key to end)
91|r| replace a single character (doesn't require Esc key to end)
92|R| replace or over-type
93|A| append starting at the end-of-line
94|o| add text after the current line (open a line)
95|O| add text before the current line
96|o| add text after the current line (open a line) (oh)
97|O| add text before the current line (capitol oh)
98|cw| change word
99|S| replace the current line with entered text
100
101
102!!Deletion
103
104|x| delete one character
105|X| delete previous character
106|dd| delete current line
107|dw| delete word
108|d$| delete to end-of-line
109|D| delete to end-of-line
110
111(Remember that any command can be preceded by a number so things line
1125dd means delete 5 lines, 7x means delete 7 characters)
113
114
115!!Searching
116
117|/xxxxx<return-key>| search forward for xxxxx
118|?xxxxx<return-key>| search backwards for xxxxx
119|/xxxxx<return-key>| search forward for regular expression xxxxx
120|?xxxxx<return-key>| search backwards for regular expression xxxxx
121|n| repeat previous search
122
123Vi's regular expression syntax corresponds to grep's basic regular expression syntax. See [grep]
124
125
126!!Cutting, copying and pasting
127
128Cutting is done with the delete commands listed above.\\
129|yy| yank (copy) line
130|yw| yank (copy) word
131|y$| yank (copy) to end-of-line
132|p| Put or paste. Basically it pastes the last line (or group of lines) after the current position.
133|kp| Useful after a delete if you didn't really want to delete but just copy the text. The kp puts it back where it was but remembers what was deleted.
134
135Remember that these commands can be proceeded with a number to get a
136group of words or a group of lines.
137
138!!Misc
139
140|J| join the next line to the end of the current line
141|u| undo last edit
142|:e!|undo all changes since last save
143|.| repeat last text-changing command
144|:.=| display current line number
145|:set autoindent|turn on auto-indent mode
146|:set noautoindent|turn off auto-indent mode
147|^L|redraw screen
148|! cmd|run cmd in shell and insert result into buffer
149|!cmd|run cmd in a separate shell
150|r!cmd|run cmd in a separate shell and insert result into buffer
151
152
153----------------------------------------------------------------------
154
155!!!Advanced Commands
156
157!!Using variables (or named buffers)
158
159Copying and deleting text into variables so that you can have several
160pieces of text you are moving around. It's like being able to delete
161or copy text into a variable that you name, and then being able to
162pasted text that was put into a variable.
163
164Variable names are always single, lower-case letters so that you can
165only have 26 variables.
166
167In what follows X will be used to signify the variable name you are
168using. So, for example when you see X in a command below you will
169really put in your variable name (a through z).
170
171All copy "y" and delete "d" commands can be proceeded by "X\\
172That is double quote and your variable name. So, for example
173
174|"wdd| would delete the current line and put it in the variable named "w".
175|"v5dd| would delete the next 5 lines and put it into the variable named "v"
176|"r3yw| would copy 3 words and put them in the variable named "r"
177|"vp| would paste the contents of the variable named "v"
178
179
180!!Marking positions
181
182Marking a position allows you to save your current position into a
183variable. You can later cause the system to return to that exact
184position.
185
186|mX| save the current position in variable named at X
187|`X| return to position saved at variable named X
188
189for example:
190
191|mh| save my current position in variable named "h"
192|`h| return to position saved in variable named "h"
193
194
195!!Copying text between two files
196
197# Use any of the delete or copy (yank) commands with or without named variables.
198# Save the current file with :w
199# Edit another file with :e newfile
200# Paste as normal
201
202
203!!Search and Replace (Substitute)
204
205In what follows:\\
206|s| substitute
207|g| global
208|%| all lines
209|c| confirm
210
211!Commands:
212
213|:s/OLD/NEW/| substitute the first occurrence of OLD with NEW on current line
214|:s/OLD/NEW/g| substitute all occurrences of OLD with NEW on current line
215|:%s/OLD/NEW/g| substitute all occurrences of OLD with NEW on all lines
216|:50,100s/OLD/NEW/g| substitute all occurrences of OLD with NEW on lines 50-100
217|:%s/OLD/NEW/gc| substitute all occurrences of OLD with NEW on all lines with confirmations
218
219!!Multiple Files
220
221Vi can edit multiple files. When initially calling up VI, it may be called with multiple file names on the command line. VI supports the following commands to handle multiple files:
222
223|:n|next file is switched to
224|:N|previous file is switched to
225|:w|save the current file
226|:e newfile|edit file named newfile
227
228
229
230----------------------------------------------------------------------
231
232!!!VIM Commands
233
234VIM, a popular version of VI, has the following additional commands available to it:
235
236!!Buffers
237
238|:ls|list buffers
239|:bn|next buffer
240|:bp|previous buffer
241|:bN|switch to buffer named N (with tab completion)
242
243
244!!Windows
245
246Window commands begin with ^w. The second letter can be either the letter by itself, or at can be used as a control letter (so you don't have to release the control key if you don't want to.)
247
248!Opening and closing windows
249
250|^ws|split window horizontally
251|^wv|split window vertically
252|^wn|edit a new file in an additional / new window
253|^wc|close the window you are in
254|^wo|close all other windows
255
256! Moving cursor to different windows
257
258Use ^w followed by h, j, k, l, up arrow, down, left, or right to move the cursor to the indicated window.
259
260! Controlling the window size
261
262|^w=|Make all windows equal size
263|^w-|Make current window smaller (also takes prefix argument)
264|^w+|Make current window larger (also takes prefix argument)
265
266
267!! Editing remote files
268
269vim scp://username@host.com/path/to/file
270
271:e scp://username@host.com/path/to/file
272
273!! VIM Startup
274
275When vim starts up, it reads the file ~/.vimrc
276
277You can put configuration commands in that file.
278
279! Stopping the colors
280
281Put the following in .vimrc
282
283{{{syntax off}}}
284
285
286
287
288
289