Wednesday, February 2, 2011

VI Editor Tips

The VI editor is a screen-based editor used by Linux/Unix users. The VI editor has powerful features to aid programmers.  VI has two modes insertion mode and command mode.  The editor begins in command mode. Insertion mode begins upon entering an insertion or pressing 'i' in keyboard. [ESC] returns the editor to command mode.

Following tips may be helpful for programmers / content writers.
Execute the command from VI Editor command mode. (press Esc, If Insert mode)


Insert space/character between 2 adjacent characters

Example 1
'LinuxFor' becomes 'Linux For' (Sentence Case)

:%s/\([a-z]\)\([A-Z]\)/\1 \2/g

Example 2
'Kerala government' becomes 'Kerala Governemnt'

:%s/\([a-z]\) \([A-Z]\)/\1 \U\2/g


Removes all lines starts with a word/patterrn.

Removes all lines begin with 'Ele'

:g/^Ele.*$/d

Removes all lines end with 'are'

:g/$*.are/d

Removes blank lines

:g/^$/d

Make First Letter Capital

:%s/^./\U&/