Jun 06

vi Tips and Tricks

Delete lines that contain string:
:g/string/d

Turn on|off line numbering:
:set [nu|nonu]

Number lines (filter the file through a unix command and replace with output):
:%!cat -n

Sort lines:
:%!sort

Sort and uniq:
:%!sort -u

Set textwidth for automatic line-wrapping as you type:
:set textwidth=80

Turn on|off syntax highlighting
:syn [on|off]

Force the filetype for syntax highlighting:
:set filetype=php

Use lighter coloring scheme for a dark background:
:set background=dark

This post has been viewed 742 times.

Leave a Reply