中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 操作系统 > 综合文章
Vi Summary
作者:未知 时间:2005-09-13 23:22 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:Vi Summary
Simple guide to use Vi

The vi Text Editor.

The vi text editor can be used to edit ASCII text files while you are working in a shell window. It is a standard editor found on most unix systems. To open or create a file in vi, from your command line type:

vi filename

If you are creating a new file, filename is what you want to call the file. If you are editing an existing file, type the current filename. The file appears in your shell window.

Unlike most word processors you may be familiar with, vi has two modes of operation that you must toggle back and forth between in order to edit your files. One mode is for inserting text, and the other mode is for moving around or executing commands. The two modes are called:

  1. Text Input mode. (also called insert mode)
  2. Command mode (also called escape mode)
When you first enter vi, you are in command mode, and cannot enter text until you change modes. You can switch to Text input mode by hitting the i key (for insert). After hitting the i key, any characters you type will be inserted at the current cursor position. Alternatively you could enter insert mode by pushing the a key (for append), and characters you type will be appended to the current cursor position. To get back to escape mode you push the escape key. You need to be in Command mode before you can quit out of a file.
Short summary of vi Commands.

Use the following commands in Command mode to cut, paste, and move around in the text. Use them also to switch from Command mode to Text Input mode. Remember to hit <Esc> or <CTRL 3> whenever you want to switch from Text Input mode to Command mode.


Adding Text in vi

Use these Command mode keystrokes to switch to Text Input mode (hit <Esc> or <CTRL 3> to return to Command mode):

a Add text after the cursor.
A Add text to the end of the current line.
i Insert text at the cursor.
I Insert text at the beginning of the current line.
o Open a new line below the current line and add text.
O Open a new line above the current line and add text.
s Substitute the letter underneath the cursor with letter you type, and insert text.
S or c Delete the current line and substitute it with text you type.
R or C Replace current text with text you type.


Cutting and Pasting Text in vi

Use these Command mode keystrokes to cut and paste text:

x Delete the letter beneath the cursor.
dw Delete the letter beneath the cursor and the rest of the word.
# dw Delete the following number of words, including the current word.
D Delete from the cursor to the end of the line.
dd Delete the current line.
# dd Delete the following number of lines, including the current line.
yy Copy or "yank" the current line.
# yy Copy or "yank" the following number of lines, including the current line.
p Paste the current copied or deleted letters, words, or lines after the cursor.
J Join the next line with the current line (erases a carriage return).
u Undo the last edit.
. Redo the last editing command.


Moving Around in a vi Text File

Use these Command mode keystrokes to move around within the file:
j Move down to the next line.
k Move up to the previous line.
h Move backward by letter.
l Move forward by letter.
w Move forward by word.
b Move backward by word.
e Move forward to the end of a word.
CTRL F Move forward to next screen.
CTRL B Move backward to previous screen.
CTRL D Move forward one-half of a screen.
G Move to the end of the file.
# G Move to the specified line number in the file.
$ Move to the end of the current line.
0 Move to the beginning of the current line.
/ wordSearch for specified word.
n Search for next occurrence of specified word.
N Search for previous occurrence of specified word.


Saving or Quitting vi

Use these Command mode keystrokes to save or quit out of a file:
:wq or ZZ Save and quit out of the file.
:w Save the current file without quitting.
:q Quit if no edits have occurred.
:q! Quit without saving edits.

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有