edit (一个文本编辑器)

rose1 发表于 2020-09-04 09:06
浏览次数:
在手机上阅读

在类似Unix的操作系统上,edit命令是一个文本编辑器。

查看英文版

目录

1 edit 运行系统环境

2 edit 说明

3 edit 语法

4 edit 例子

edit 运行系统环境

Linux

edit 说明

edit是文本编辑器ex的变体。对于希望使用面向命令的编辑器的新用户或临时用户,建议使用它。它具有ex的功能,并自动设置了以下选项:

  • novice 
  • report 
  • showmode 
  • magic 

以下简要介绍应该可以帮助您开始使用edit。如果使用的是CRT 终端,则可能需要了解显示编辑器vi。要编辑现有文件的内容,请从以下命令开始:

编辑文件名

edit将复制文件FILENAME,然后可以对其进行编辑。它首先告诉您文件中有多少行和字符。如果文件不存在,则edit会告诉您它是[新文件]。

该编辑命令提示符是一个冒号(:),你应该启动编辑器后看到的。如果要编辑现有文件,则edit缓冲区中有几行(其名称表示您正在编辑的文件的副本)。当您开始编辑时,编辑会使文件的最后一行成为当前行。如果您不告诉他们要使用哪一行,则大多数要编辑的命令都会使用当前行。因此,如果您说出print(可以缩写为p)并输入回车符(在所有edit命令之后都应输入),则当前行将被打印。如果删除(d)当前行,请编辑打印新的当前行,通常是文件中的下一行。如果删除最后一行,则新的最后一行将成为当前行。

如果您从一个空文件开始或希望添加一些新行,则可以使用append(a)命令。执行此命令(在append后面键入回车符)后,edit将从终端读取行,直到键入仅由点(。)组成的行;它将这些行放置在当前行之后。您键入的最后一行将成为当前行。insert(i)命令类似于append,但是将您键入的行放在当前行之前而不是之后。

edit工具号码在缓冲器中的行,与具有数的第一行1。如果执行命令1,则edit键入缓冲区的第一行。如果然后执行命令d,则edit删除第一行,第2行变为第1行,然后edit打印当前行(新行1),以便您看到自己所在的位置。通常,当前行始终是受命令影响的最后一行。

您可以使用replace(s)命令更改当前行中的某些文本:

s/old/new/

其中,老的是字符串要替换的字符和新是要替换的字符的字符串老带。

filename(f)命令告诉您正在编辑的缓冲区中有多少行,如果您更改了缓冲区,则说[Modified]。修改文件后,您可以通过执行write(w)命令来保存文件的内容。您可以通过发出quit(q)命令离开编辑器。如果对文件运行edit但不进行更改,则无需(但不会造成损害)将文件写回。如果你尝试戒烟从编辑修改缓冲区但不写出来后,您会收到消息“ 自去年变化没有写(:退出覆盖!) ”,并编辑等待另一个命令。如果您不想写出缓冲区,请发出quit命令,后跟一个感叹号(q!)。然后,该缓冲区将被不可挽回地丢弃,然后您将返回到外壳。

通过使用d和命令并提供行号以查看文件中的行,可以进行所需的任何更改。但是,如果多次使用编辑,则应该至少学到一些东西。

change(c)命令将当前行更改为您提供的一系列行(如附录中所示,将行键入直到仅包含点(。)的行。您可以通过以下命令告诉change更改多行:您要更改的行的行号,即3,5c,您也可以用这种方式打印行:1,23p打印文件的前23行。

undo(u)命令撤消您执行的最后一个更改缓冲区的命令的效果。 因此,如果您执行的替代命令无法执行您想要的操作,请键入u并恢复该行的旧内容。 您也可以撤消撤消命令。 当命令影响缓冲区的多行时,edit给您一条警告消息。 请注意,诸如写和退出之类的命令无法撤消。

要查看缓冲区中的下一行,请输入回车符。要查看多行,请键入^ D(按住Ctrl键的同时按d键),而不要输入回车符。这显示了CRT上的半行屏幕或硬拷贝终端上的12行。您可以通过执行z命令来查看附近的文本。当前行出现在显示的文本的中间,最后显示的行成为当前行;您可以通过输入''返回执行z命令之前的行。 z命令还有其他选项:z-打印一个以您所在的位置结尾的文本屏幕(或24行); z +打印下一屏。如果您希望少于一屏的行,请键入z.11以在当前行之前显示五行,在当前行之后显示五行。 (键入zn时,当n为奇数时,将显示总共以当前行为中心的n行;当n为偶数时,将显示n-1行,因此显示的行将以当前行为中心。 )您可以在其他命令之后计数;例如,您可以使用命令d5删除从当前行开始的5行。

要在文件中查找内容,如果碰巧知道行号,可以使用行号;否则,可以使用行号。由于插入和删除行时行号会更改,因此这有些不可靠。您可以通过以下形式的命令在文件中向后或向前搜索字符串:/ text /,以向前搜索文本或?。文字?向后搜索文本。如果搜索到达文件末尾而没有找到文本,它将环绕并继续搜索回到您所在的行。此处的一个有用功能是搜索/ ^ text /形式,它在一行的开头搜索文本。同样/文本$ /在行尾搜索文本。您可以省略尾随的/或?在这些命令中。

当前行的符号名称为点(。);这在。,$ p中的行范围中最有用,它打印当前行以及文件中的其余行。要移至文件的最后一行,可以用其符号名$引用它。因此,无论当前行是什么,命令$ d都会删除文件中的最后一行。也可以使用行引用进行算术运算:$ -5行是最后一行之前的第五行,。+ 20是当前行之后的20行。

您可以通过键入' 。= ' 找到当前行。如果要在文件内或文件之间移动或复制一段文本,这将很有用。找到您要复制或移动的第一行和最后一行。要在第10行到第20行之间移动,请键入10,20d a以从文件中删除这些行,并将它们放置在名为a的缓冲区中。edit有26个这样的缓冲区,称为a到z。要将缓冲区a的内容放在当前行之后,请输入put a。如果要将这些行移动或复制到另一个文件,请在复制这些行之后执行edit(e)命令;否则,请执行以下操作:跟随e命令,并带有要编辑的另一个文件的名称,即edit Chapter2。要复制行而不删除行,请使用yank(y)代替d。如果要移动或复制的文本都在一个文件中,则不必使用命名缓冲区。例如,要将第10行到20行移动到文件末尾,请键入10,20m $。

edit is a variant of the text editor ex. It's recommended for new or casual users who wish to use a command-oriented editor. It operates precisely as ex with the following options automatically set:

  • novice ON
  • report ON
  • showmode ON
  • magic OFF

The following brief introduction should help you get started with edit. If you are using a CRT terminal you might want to learn about the display editor vi. To edit the contents of an existing file you begin with the command:

edit FILENAME

edit makes a copy of the file FILENAME which you can then edit. It first tells you how many lines and characters are in the file. If the file does not exist, edit tells you it is a [New File].

The edit command prompt is a colon (:), which you should see after starting the editor. If you are editing an existing file, then you have some lines in edit's buffer (its name for the copy of the file you are editing). When you start editing, edit makes the last line of the file the current line. Most commands to edit use the current line if you do not tell them which line to use. Thus if you say print (which can be abbreviated p) and enter a carriage return (as you should after all edit commands), the current line is printed. If you delete (d) the current line, edit prints the new current line, which is usually the next line in the file. If you delete the last line, then the new last line becomes the current one.

If you start with an empty file or wish to add some new lines, then the append (a) command can be used. After you execute this command (typing a carriage return after the word append), edit reads lines from your terminal until you type a line consisting of just a dot (.); it places these lines after the current line. The last line you type then becomes the current line. The insert (i) command is like append, but places the lines you type before, rather than after, the current line.

The edit utility numbers the lines in the buffer, with the first line having number 1. If you execute the command 1, then edit types the first line of the buffer. If you then execute the command d, edit deletes the first line, line 2 becomes line 1, and edit prints the current line (the new line 1) so you can see where you are. In general, the current line is always the last line affected by a command.

You can make a change to some text within the current line by using the substitute (s) command:

s/old/new/

where old is the string of characters you want to replace and new is the string of characters you want to replace old with.

The filename (f) command tells you how many lines there are in the buffer you are editing and says [Modified] if you have changed the buffer. After modifying a file, you can save the contents of the file by executing a write (w) command. You can leave the editor by issuing a quit (q) command. If you run edit on a file, but do not change it, it is not necessary (but does no harm) to write the file back. If you try to quit from edit after modifying the buffer without writing it out, you receive the message "No write since last change (:quit! overrides)", and edit waits for another command. If you do not want to write the buffer out, issue the quit command followed by an exclamation point (q!). The buffer is then irretrievably discarded and you return to the shell.

By using the d and a commands and giving line numbers to see lines in the file, you can make any changes you want. You should learn at least a few more things, however, if you use edit more than a few times.

The change (c) command changes the current line to a sequence of lines you supply (as in append, you type lines up to a line consisting of only a dot (.). You can tell change to change more than one line by giving the line numbers of the lines you want to change, that is, 3,5c. You can print lines this way too: 1,23p prints the first 23 lines of the file.

The undo (u) command reverses the effect of the last command you executed that changed the buffer. So if you execute a substitute command that does not do what you want, type u and the old contents of the line are restored. You can also undo an undo command. edit gives you a warning message when a command affects more than one line of the buffer. Note that commands such as write and quit cannot be undone.

To look at the next line in the buffer, type a carriage return. To look at a number of lines, type ^D (while holding down the control key, press d) rather than carriage return. This shows you a half-screen of lines on a CRT or 12 lines on a hardcopy terminal. You can look at nearby text by executing the z command. The current line appears in the middle of the text displayed, and the last line displayed becomes the current line; you can get back to the line where you were before you executed the z command by typing ''. The z command has other options: z- prints a screen of text (or 24 lines) ending where you are; z+ prints the next screenful. If you want less than a screenful of lines, type z.11 to display five lines before and five lines after the current line. (Typing z.n, when n is an odd number, displays a total of n lines, centered about the current line; when n is an even number, it displays n-1 lines, so that the lines displayed are centered around the current line.) You can give counts after other commands; for example, you can delete 5 lines starting with the current line with the command d5.

To find things in the file, you can use line numbers if you happen to know them; since the line numbers change when you insert and delete lines this is somewhat unreliable. You can search backwards and forwards in the file for strings by giving commands of the form /text/ to search forward for text or ?text? to search backward for text. If a search reaches the end of the file without finding text, it wraps around and continues to search back to the line where you are. A useful feature here is a search of the form /^text/ which searches for text at the beginning of a line. Similarly /text$/ searches for text at the end of a line. You can leave off the trailing / or ? in these commands.

The current line has the symbolic name dot (.); this is most useful in a range of lines as in .,$p which prints the current line plus the rest of the lines in the file. To move to the last line in the file, you can refer to it by its symbolic name $. Thus the command $d deletes the last line in the file, no matter what the current line is. Arithmetic with line references is also possible: the line $-5 is the fifth before the last and .+20 is 20 lines after the current line.

You can find out the current line by typing '.='. This is useful if you want to move or copy a section of text within a file or between files. Find the first and last line numbers you want to copy or move. To move lines 10 through 20, type 10,20d a to delete these lines from the file and place them in a buffer named aedit has 26 such buffers named a through z. To put the contents of buffer a after the current line, type put a. If you want to move or copy these lines to another file, execute an edit (e) command after copying the lines; following the e command with the name of the other file you want to edit, that is, edit chapter2. To copy lines without deleting them, use yank (y) in place of d. If the text you want to move or copy is all within one file, it is not necessary to use named buffers. For example, to move lines 10 through 20 to the end of the file, type 10,20m $.

查看英文版

查看中文版

edit 语法

edit [ -| -s ] [ -l ] [ -L ] [ -R ] [ -r [ filename ] ] [ -t tag ] [ -v ] 
     [ -V ] [ -x ] [ -wn ] [ -C ] [+command | -c command ] filename

选件

-, -s 禁止所有交互式用户反馈。在处理编辑器脚本时,这很有用。
-l 设置用于编辑LISP程序。
-L 列出由于编辑器或系统崩溃而保存的所有文件的名称。
-R 只读模式;设置了只读标志,以防止意外覆盖文件。
-r 文件名 在编辑器或系统崩溃后编辑文件名。(恢复发生崩溃时缓冲区中文件名的版本。)
-t 标签 编辑包含标签标签的文件,并将编辑器置于其定义位置。
-v 使用vi在显示编辑状态下启动。您可以通过键入vi命令本身来达到相同的效果。
-V 详细模式。当通过标准输入读取ex命令时,输入将回显到标准错误。在shell脚本中处理ex命令时,这可能很有用。
-x 加密选项;使用时,edit模拟exX命令并提示用户输入密钥。该密钥用于使用crypt命令的算法对文本进行加密和解密。的X命令使一个受过教育的猜测,以确定文本是否在被加密或不读出。临时缓冲区文件也使用-x选项键入的键的转换版本进行加密。
-wn 将默认窗口大小设置为n。在较慢的速度线上使用编辑器时,这很有用。
-C 加密选项;与-x选项相同,除了vi模拟exC命令。该Ç命令是像X的命令前,除了所有文字,被认为已经加密阅读。
+ 命令,- 命令 通过执行指定的编辑器命令(通常是搜索或定位命令)来开始编辑。
文档名称 您要编辑的文件的名称。
edit [ -| -s ] [ -l ] [ -L ] [ -R ] [ -r [ filename ] ] [ -t tag ] [ -v ] 
     [ -V ] [ -x ] [ -wn ] [ -C ] [+command | -c command ] filename

Options

--s Suppress all interactive user feedback. This is useful when processing editor scripts.
-l Set up for editing LISP programs.
-L List the name of all files saved as the result of an editor or system crash.
-R Read only mode; the read only flag is set, preventing accidental overwriting of the file.
-r filename Edit filename after an editor or system crash. (Recovers the version of filename that was in the buffer when the crash occurred.)
-t tag Edit the file containing the tag tag and position the editor at its definition.
-v Start up in display editing state using vi. You can achieve the same effect by typing the vi command itself.
-V Verbose mode. When ex commands are read by means of standard input, the input will be echoed to standard error. This may be useful when processing ex commands within shell scripts.
-x Encryption option; when used, edit simulates the X command of ex and prompts the user for a key. This key is used to encrypt and decrypt text using the algorithm of the crypt command. The X command makes an educated guess to determine whether text read in is encrypted or not. The temporary buffer file is encrypted also, using a transformed version of the key typed in for the -x option.
-wn Set the default window size to n. This is useful when using the editor over a slow speed line.
-C Encryption option; same as the -x option, except that vi simulates the C command of ex. The C command is like the X command of ex, except that all text read in is assumed to have been encrypted.
+command, -command Begin editing by executing the specified editor command (usually a search or positioning command).
filename The name of the file that you want to edit.

查看英文版

查看中文版

edit 例子

edit myfile.txt

加载myfile.txt以进行编辑,然后将用户置于编辑命令提示符处。

edit myfile.txt

Loads myfile.txt for editing, and places the user at the editing command prompt.

查看英文版

查看中文版

其他命令行

echo | eject | elm | enable | env | ex | exit | expand | expr | egrep |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条