Skip to content

vi Notes

Guide to vi editors.
=====================

o appends below – 10oEscape – appends 10 lines below
O appends above – 10OEscape – appends 10 lines above
(Otherwise o allows immediate editing after being pressed)

:set wrapmargin=8 (sets margin to col 72 on 80 margin screen)
:set ai
:set noai
:w filename
:w ! writes the file as input to a unix command.
ZZ to exit
navigate:
———-
w,b stops on . and , but W,B does not.
10+ moves fwd 10 lines
10- moves back 10 lines 😀 really cool !!!

n with
h , j , k , l

<-, | , ^, ->
v   |

To set all properties of vi use the file .exrc in your home directory.
^ Start , $ End

search
————
/forward search
?backward search

f + character – fwd search for character
F + character – backward search for character
w = word search fwd to start of word,
b = backward search word,
e forward to end of word.

edit
—————–
dG  deletes current line + all below till end.
d1G deletes current + all above till start.
d+3 deletes fwd 3 lines
d-3 delets bkwd 3 lines
dw,db , d3w , d3b, dfc,dFc
d) d till end of sentence d} – till end of para.

COOL -> delete till a pattern = d/searchpattern(fwd search) or d?searchPattern = bckwd search

Delete 4 lines = 4dd or 3d+ or d3+

Note—–> All data deleted,yanked is put in buffer
To get from buffer
p = paste after cursor
P = paste before cursor
changing case (Loved this) = tilde = ~
r replace single char / R replace all chars in current line
s also replace char (but first delets and enters into INSERT mode) 3s = 3 substitutes.
cw = change word ,
cc,c$ = change line,  c+, c3+ or c- , c3-
2c+enter , change 2 lines =  2c+ or 2c-

SWAP WORDS
dwwP,or  dWWP = swap words
ddP  = swap lines
SHIFT
>> right
<< lift

cOPY: :10,50 ya = yank
join: :j! or :j40
Copy another file in current :r file_name

REGEX
============
:%s/pattern/replace/global
:g/pattern/d = delete every line having pattern

When using line oriented cursor controls(j,k,l,h) the change affects the current line whereas the text oriented cursor controls(w,b) affter the change from the present cursor location.

UTILITIES:
==============
:%s/^$/d

Q: How to mark and copy from a specific buffer?

To start copy –          ma

To end copy –            y`a

And paste –                 p

To paste with cut use d`a instead of y`a.

Q: How to get count of files under the given directory?
Do not save the file in windows and then run it in unix. It gives a error with /r carriage feed. Window uses /n and /r for new line Unix uses only /n so error on encountering /r

%d bloggers like this: