ex editor

In vi you have edit mode, insert mode and visual mode.
For insert mode press i, edit mode esc, visual v.
In edit mode, move left press h, down h, up k, rigth l.

In edit mode, you can send commands to ex editor.
The colon : tells vi to invoke ex:

Temporarily display the line number of a set of files, :1,10#
Print total number of files, :=
Print current line number, :.=

View line numbers: :set nu
Not view line numbers::set nonu
Search with case insensitive: :set ic
Search with case sensitivte: :set noic

Delete from current line to end of file, :.,$d
Delete from line 20 to current line, :20,.d
Delete all lines in file :%d

Search a pattern and print the following 10 lines, :/pattern/;+10 p

Read the contents of a file2 into the current file, :r file2. Content of file2 is inserted at current cursor position.

Open a file in a new tab, while editing one already, do : tabe [file_name]
Move to previous tab : tabp
Move to next tab : tabn
View all opened files : args

View the file in hexa mode do :%!xxd

Save and exit :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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s