29 8 月 2012

vi – UNIX最流行的編輯器,Execution Mode

vi text editor execution mode introduction

Execution Mode

Now we’ll introduce Execution Mode command so please type in colon (:) under Command Mode to enter in Execution Mode.

Execute external command without quitting from vi

:!< command >

Type in command line “:!bash” if for executing bash without quitting vi. Typing in exit can quit bash to go back vi.

For senior system administrator or programmer, such function can make user execute other programs or commands without quitting vi to massively improve work efficiency. For example, just type in “:!date” if for date information.

vi – Execution Mode (Import File Contents)

vi text editor execution mode import file content function
Import target file contents or command output data
:r< file name >

Example: :r /etc/passwd
The file contents will be imported after cursor without using Append Redirection.

vi – Execution Mode (Import Command Output)

vi text editor execution mode import command and output function
Type in the command line “:r date” to import the output of date command
:r! < command >

Example: :r!date
The output of date command will be imported after cursor.

Save as new file:
:w< file name >
Like Windows notepad, it will stay in original text editing after saving text as new file.

Compulsive symbol (!):
:q! – quit without saving
:w! – Force to save without modifying access permission if user has file modification but no access permission
:wq! – Force to save and quit without modifying access permission if user has file modification but no file access permission