|
8.00 Vim
8.01 Help
Vimtutor
:help
CTRL-] jumps to the linked
text
CTRL-o jumps back to
where you were in the help text
CTRL – L refresh the
screen
8.02 Start Vim
vim (starts
vim)
vi filename
(edit filename )
vim -R view
FILENAME (vies files without changing them. (Read only)
vim -r
(checks for swap files (after vim crash, helps to locate and
recover the file)
8.03 Exit
:q!
exit without saving
:wq
save and exit
:w FILENAME
to save changes made to the file
: #,# w FILENAME
to save between line this and that
ZZ
write your newly entered text to the disk and end the editing session
8.04 Moving the Cursor
h
left one character
l
right one character
j
down one line
k
up one line
0(zero) move
cursor to start of current line (the one with the cursor)
$ move cursor to the
end of current line
w
move cursor to the beginning of next word
b
move cursor back to the begining of preceding word
1G move
cursor to first line in the file
nG move
cursor to line (n-number)
G move
cursor to the last line in file
Number l/h
moves cursor times the number specified. (l-right, h-left)
8.07 Screen Manupulation
Ctrl b backward
one screen
Ctrl d
down(forward) one half screen
Ctrl u up
(back) one half screen
Ctrl l
redraws the screen
Ctrl r
redraws the screen
8.06 Inserting Text
i insert
text
I insert
text at the beginning of current line
a append
text after cursor
A append
text to end of current line
o open
and put text in a new line below current line
O open
and put text in a line above current line
8.07 Changing Text
r replace
single character under cursor
R replace
character, starting with current position
cw change
the current word with new text, starting with the character under cursor
cNw change
N words beginning with character under cursor
C change
the character in the current line
cc change
the entire current line
Ncc change
the next N line, starting with the current line
:s/old/new/g -substitute
to replace old with new (g stand for globally)To change every occurrence
of character string between two line,
:#,#s/old/new/g -where
#, # are the number of the two lines
%s/old/new/g -to change
every occurrence in the whole file
%s/old/new/gc -ask
for the conformation
8.08 Deleting Text
x
delete single character under cursor
Nx delete
N character, starting with character under cursor
dw
delete the single word beginning with character under cursor
dNw
delete N words beginning with character under cursor; Example:
d5w deletes 5 words
D
delete the reminder of the line, starting with current cursor position
dd
delete entire current line
de
deletes from the cursor to the end of the word NOT including the space
2dd deleted
two lines from the cursor to the end of the line
8.09 Cutting and Pasting Text
yy copy
the current line into the buffer
Nyy copy
the next N lines, including the current line, into the buffer
p paste
8.10 Location adn Search
Ctrl-g show
the location in the file and the file status
/ followed
by the phrase search for the phrase
? followed
by the phrase search for the phrase in the backward direction
n searches
again
N
searches again in the opposite direction
% finds
matching ), }, ]
8.11 Determing Line Numberss
Shift-G
move to the bottom of the file. Line number followed by the command
places you in that line.
: .=
returns line number of current line at bottom of screen
:= returns
the total number of lines at bottom of screen
:set ic
ignore case in search
:set number
causes vim to display line numbers next to the typed text
:set nonumber
set number off
8.12 Saving and Reading
:r filename
read file named filename and
insert after current line (the line with cursor)
:w<enter>
write current contents to file named in original vi
call
:w newfile <enter> write current
contents to a new file named newfile
:12,35w smallfile
<enter>write contents of the lines 12 through 35
to a new file named smallfile
:w! prevfile
<enter> write current contents over a pre-existing
file named prevfile
8.13 Undo
u undo
U to
fix the whole line
:redo
vim will redo the undone command
CTRL-R
redo the command
p put
last deletion after the cursor
r (chr) to
replace character under the cursor
cw to
change part or all of a world (places you in Insert mode, (w-word, $-end
of line))
:!
followed by the external command to execute the command
|