[TriLUG] need help from the vi gurus

Stephen Hoffman srhoffman at hofftech.net
Tue Dec 9 08:50:02 EST 2003


Entering vi

% vi name          edit name at top
% vi +n name       edit name at line n
% vi + name        edit file at the end
% vi -r            list saved files
% vi -r name       recover file name
% vi name1 name2   edit name1 first, rest via :n
% vi +/pat name    search file for pat

File Manipulation

:w            write back changes
:wq           write and quit
:q            quit
:q!           quit and discard changes
:e name       edit the file name
:e!           reedit, discard changes
:e +n         edit starting at line n
:w name       write file name
:w! name      overwrite file name
:n            edit next file in arglist

Cursor Motion

                    back            forward
letter              ^H, h           <space>
word end                            E, e
word beginning       B, b           W, w
sentence             (              )
paragraph            {              }
section              [[             ]]
line ends            0              $
  1st char           -              +
  same column       ^P             ^N, <linefeed>
  specified line    <line#>G       <line#>G
1/2 screenful jump  ^U             ^D
screenful jump      ^B             ^F


Undo

u      undo last change
U      restore current line
"#p    retrieve #th last delete
<esc>  abandon incomplete command
:q!    (drastic) quit without save

Insert

i      before cursor
I      before first nonblank
a      after cursor
A      after line
o      open line below
O      open line above
p      paste last cut
<esc>  terminates insert

Change

cw
<newword>  change word
C            substitute line
s<char>      substitute char
S            substitute lines
r<char>      replace char
R            replace chars (overstrike)
xp           transpose chars (cut paste)
<esc>        terminates change


Delete

x     char under cursor
X     char before cursor
dw    word
de    delete word but leave punctuation
dd    line
#dd   # lines
D     rest of line


Delete during Insert

^H    last char
^W    last word
@     all input this line


Miscellaneous Operations

J      join lines
:sh    run shell, then return
:!cmd  execute a command, then return
:f     show current file and line
^g     same as :f

Numbers etc.

. (period)  repeat last action
3.          repeat it 3 times
3dd         delete 3 lines
d3w or 3dw  delete 3 words
3rx         replace next 3 chars with x




More information about the TriLUG mailing list