San Francisco

dave spink toolset


Vi EDITOR:

CUSTOMISE SESSION INPUT CMDs MOVEMENT DELETING TEXT
COPY AND PASTE BRINGING IN TEXT MODIFYING SAVING AND QUIT
EDITING


THE PROJECT

To document my commonly used "vi" commands.



CUSTOMISE SESSION

:set showmode ;see what mode you are in
:set noshowmode ;turns this off
:set nu ;show line numbers
:set nonu ;turns this off
:set ic ;ignore case on search
:set list ;display invisible chars
:set nolist ;hide invisible chars
:set ;display all variable set
:set all ;displays all possible vi variables and their current settings
.exrc ;create in home dir, one cmd per line without the :




INPUT CMDs

a ;append after cursor
A ;append at line end
i ;insert before cursor
I ;insert at beginning of the line
o ;opens a new line below cursor
O ;opens a new line above cursor




MOVEMENT

h ;left one char
l ;right one char
j ;down one line
k ;up one line
w ;forward one word
b ;backward one word
e ;end of current word
0 or ^ ;moves beginning of line
^ ;goto line start
$ ;goto line end
G ;goto last line
1G ;goto first line
:21 ;goto line 21
21G ;goto line 21
^F ;forward one screen
^B ;backward one screen
^D ;down half a screen
^U ;up half a screen
^L ;refreshes screen




DELETING TEXT

x ;deletes one char
dw ;deletes one word
dd ;deletes one line
D ;deletes to end of line
4dd ;deletes four lines
:5,10d ;deletes lines 5 through 10




COPY AND PASTE

5yy ;yank a copy of 5 lines
p ;put below cursor
P ;put above cursor
:1,3 co 5 ;copies lines 1 through 3 and put on line 5
:4,6 m 8 ;moves lines 4 through 6 to line 8




BRINGING IN TEXT

:r file ; insert file at line after cursor
:!cmd ;execute command




MODIFYING

cw ;change word
3cw ;change 3 words
c3w ;as above
C ;change line
R ;replace word
r ;replace char
u ;undo previous cmd
U ;undo all changes to the line
J ;join current line and line below
xp ;transposes chars
~ ;change case of letter
:/fred ;search forward for the string fred
n ;next occurrence
:?fred ;search backwards for the string fred
N ;previous occurrence




SAVING AND QUIT

:w ;save
:w file ;save to new file
:wq ;save and quit
:x ;save and quit
ZZ ;save and quit
:q! ;quit without saving
:wq! ;save, quit and override read only




EDITING

:.,+20s/^/aaa ;from current line, for next 20 lines, at beginning of the line insert aaa
:%s/old/new/g ;searches and replaces globally