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