Useful commands in vi to delete

Useful commands in vi:
To delete lines
One at a time: <esc>dd
n lines at a time: <esc>ndd – where n is the number of lines to be deleted, eg: 3dd would delete 3 lines

To delete all blank lines (lines that don’t have spaces in between): <esc>:g/^$/d
To delete all blank lines that have spaces in them: <esc>:g/^ *$/d
To delete from current cursor position to end of line: <esc>d$ or <esc>D
To delete from current cursor position to beginning of line: <esc>d0
To delete word from current cursor position forward: <esc>dw
To delete word from current cursor position backward: <esc>db
To delete current character: <esc>dl or <esc>x
To delete one character backward: <esc>dh or <esc>X

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s