| Change case/text with tr | |
~ |
swap lowercase
|
:.!tr '[a-z]' '[A-Z]' |
swap current line to uppercase (mandatory spaces) |
|---|---|
w~ |
change case to next word (capitalize) |
b~ |
change case to previous or current word (capitalize) |
:.!tr '{}' '()' |
change curly brackets to parenthesis |
| Overstrike | |
r |
replace one char at cursor pos |
nr |
repeat n times the char to be replaced at cursor pos |
R |
replace text until <esc> at cursor pos |
nR |
insert n times text replaced until <esc> at cursor pos |
| Insert | |
s ns |
replace one or n chars with text until <esc> at
cursor pos |
S |
delete current line and replace text until <esc> |
| Change Lines | |
cc ncc |
change current or n lines beginning at current line |
cG c1G |
change all lines starting at current line to EOF or BOF |
cnG |
change all lines starting at current line to line n |
| (forward or backward depending on pos of line n relative | |
| to current line) | |
c- nc- |
change current and preceding or n lines |
c+ nc+ |
change current and following or n lines |
C c$ |
change all chars from current cursor pos to EOL |
c0 c| |
change all chars from column 1 to char preceding cursor pos |
| Change Words | |
cw ncw |
change from cursor pos to end of current or n words |
cb ncb |
change from nearest or n preceding BOW to char before |
| current cursor pos | |
| Change Text Sections | |
c) |
change from cursor pos to next EOSentence |
c( |
change from preceding SOSentence to char before cursor |
c} |
change from cursor pos to next EOParagraph |
c{ |
change from preceding SOParagrapf to char before cursor |
c]] |
change from cursor pos to next EOSentence |
c[[ |
change from preceding SOSection to char before cursor |
Changing text such as words, sentences or paragraphs is not restricted to the current line. If the number of specified objects exceeds current line contents, the change operation is extended until the text specification is completely satisfied.
Case is changed by the vi built-in command ~ that swaps case. The
tolower/toupper functions are achieved by the tr command in ex
mode.
N.B. tr applies to the current line or to any specified line
range, like in the following ex example:
:24,25!tr '[a-z]' '[A-Z]'
therefore to change the case of single words the ~ command must be
used with an appropriate repeat count.
No vi or tr function is used to capitalize words, thus the vi
combined commands w~ or b~ must be used to change case of word
initials in forward or backward direction.
Overstrike operation is achieved with n r that overwrites the current
character(s) with the charcater typed after r. More chracters are
overwritten up to <esc> by R. n R oversrtikes n
characters and appends n times the typed characters.
While R overstikes the following characters, s overstrikes
(substitues) only the cursor charatcer and inserts the following one up to
<esc>.
Finally S substitutes the current line in the same way as cc.
| Examples of r, R, s, S | |
brrend a quite full line |
current line of text |
0rA |
change first char to A |
2rp |
change next two chars to rr |
Append a quite full line |
current line after changes |
02w2Rvery |
change quite to very very |
Append a very very full line |
current line after changes |
02sPre<esc> |
change Append to Prepend |
Prepend a very very full line |
current line after changes |
SThe end<esc> |
change whole line with S, same as cc |
The end |
current line after line subsitution |
| n.b. - In the above examples |
|
| Change Text Sub-sections | |
cfc cnfc |
change from cursor pos to first or nth occurrence of c on |
current line forward to EOL until <esc> |
|
cFc cnFc |
change from cursor pos to first or nth occurrence of c on |
current line backward to BOL until <esc> |
|
ctc cntc |
change from before cursor pos to first or nth occurrence of |
c on current line forward to EOL until <esc> |
|
cTc cnTc |
change from before cursor pos to first or nth occurrence of |
c on current line backward to BOL until <esc> |
|
| Change Pattern Matching Text Sub-sections | |
c/pattern<ret> |
change from cursor pos to first occurrence of pattern |
| forward to EOF (not including pattern ). | |
| If search wraps to BOF before pattern is matched, change | |
| begins with pattern and all text is removed up to, but not | |
| including, current cursor pos. | |
c?pattern<ret> |
change from cursor pos to first occurrence of pattern backward |
| to BOF. If pattern is matched before BOF is reached, change | |
| starts with pattern up to, but not including, current cursor | |
| pos. If search wraps to EOF before pattern is matched, change | |
| begins with cursor pos up to, but not including, pattern . | |