4/

vi Reference



Almost any movement/change can be preceeded with a numeric count.

MOVEMENT:

hjkl

left down up right

w

word

b

back (word)

Shift [wb]

find blank delimited word

0

beginning of line

$

end of line

_

first non-blank character


Find:

f(c)

find char 'c'

t(c)

to (stop before) 'c'

{ / }

start/end of para

( / )

start/end of sentence

/re

find regular expression 're'

?re

find backwords


Shift-find will find backwards

%

match parentheses



CHANGES:

x

delete char

rx

replace char with 'x'

s...

subs 1char w/ '...'

c(m)...

change (delete, insert) to movement 'm'

d(m)

delete to movement

i...

insert string '...' (before cursor)

a...

append string '...' after cursor

o

open new line (below) in insert mode

O

Open new line (above) in insert mode

!(m)cmd

will prompt for command, then pipe lines through the command

>

indent line

<

un-indent line


(often used as ‘count >>’ or ‘count<<’)


shift change will change to end of line

double change (eg: cc) will change whole line

shift [ia] will insert @ [start/end] of line



COMMAND MODE:

(bold indicates minimum abbreviation)

:exit

(eXit) write (if necessary), quit

:quit

quit (no changes)

:write [f]

write. If filename (f) is given, write there

:edit [f]

(re)edit -- or edit a new file (f)

:file [f]

print filename

(if 'f' given, change name of file that will be written to (f) )

Special Filenames:

%

this file

#

The last other file mentioned ("The Other file")


Line Processing

:[R]moveL

move to line L

:[R]copyL

copy to line L

:[R]delete

delete line

:[R]!cmd

pipe lines thru shell cmd

:[R]write | cmd

pipe Line into shell cmd


:subs/re/str/[gp]

substitute 're' with 'str'

g allows multiple changes per line

p prints any changed line

:global/re/cmd

execute :cmd on lines

that match expression /re/


Settings

:set

show changed settings variables

:set var=value

set variable var to value

some useful settings:

[no]number

Turn lint numbering on [off]

[no]autoindent

automatic indenting (ctrl-d to unindent)

[no[showmode

show when you are in insett

[no]ignorecase

do case insensitive searches


External commands

:!shellcommand

execute the shell command

:shell

start a shell


REGULAR EXPRESSIONS (re)

most chars match themselves, except as below:

.

matches any char

[abc0-9]

matches one of a,b or c or 0 thru 9

[^abc0-9]

matches any one character not in the set

*

any count of previous (e.g. [a-z]* would match a string of lowercase letters)

\(re\)

enclose RE (for *)

*

multiples(possibly zero)

\/

single '/'

\<,\>

start,end of word

re=//

matches last expression

^

(at beginning of string only) matches the start of the line

$

(at the end of the string only) matches the end of the line


eg: /^blahblahblah$/ would have to match the whole line.


In Replacement String:

&

is string matched

\1

is string portion matched inside first \(...\)

\2

etc.

is string portion inside second \(...\)