1/

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

(n)|

(vertical bar) move to column N of the current line


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' (see below)

?re

find backwards


Shift-find will find backwards

%

match parentheses



CHANGES:

x

Delete (extract) 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 (change name of file


that will be written to (f) )

Special Filenames:

%

this file

#

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


:[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



:substitute/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/

: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

:!shellcommand

execute the shell command

:shell

start a shell


REGULAR EXPRESSIONS (re)

most chars match themselves

.

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 as a unit

*

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.


Note: You are not limited to using the '/' character to delimit matches and replacements: most punctuation characters can be used instead.eg:

s/abc/def/ is the same as s'abc'def'

(this is most useful when you have a '/' character in your match or replacement strings)



In Replacement String:

&

is string matched

\1

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

\2

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

etc.