没有合适的资源?快使用搜索试试~ 我知道了~
首页Vi文本编辑器入门教程:屏幕操作与高效命令
Unix Vi Editor教程是一份针对Vi(Visual)文本编辑器的入门指南,由William Joy和Mark Horton撰写,两位作者均来自美国加州大学伯克利分校计算机科学系和电气工程与计算机科学系。Vi是一款专为显示界面设计的交互式文本编辑器,其核心特点是将终端屏幕视为所编辑文件的实时窗口,用户在屏幕上所做的任何修改都会实时反映在文件中。 Vi提供了丰富的功能,使得文本插入变得轻而易举。编辑器中的命令集主要围绕着光标移动展开,包括逐字符、单词、句子和段落的前后移动。这些基础操作与一组简明的删除(d)和更改(c)等操作符相结合,形成了诸如删除一个单词或更改一个段落等高级操作,命令的分配遵循一致性和记忆性原则,方便用户学习和使用。 Vi编辑器兼容众多显示终端,并且新终端的驱动通常通过编辑终端描述文件来实现,这为用户带来了便利。该教程的第1章可能介绍了Vi的基本概念、安装和配置,以及如何在各种环境下启动和操作Vi编辑器。后续章节会深入探讨更复杂的编辑技巧、模式切换(如插入模式和命令模式)、查找和替换、以及使用Vi进行文本编辑时的常用快捷键和功能。 对于初学者来说,这份教程旨在帮助他们掌握Vi的基本操作,提高文本编辑效率,同时也为进阶用户提供了一个坚实的平台,以进一步探索和定制Vi的功能。无论是日常编程工作还是系统管理,熟练掌握Vi编辑器都是一项重要的技能。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/11547189/bg8.jpg)
-- --
USD:11-8 An Introduction to Display Editing with Vi
3.6. Summary
SPACE advance the cursor one position
ˆH backspace the cursor
ˆW erase a word during an insert
erase your erase (usually ˆH or #), erases a character during an insert
kill your kill (usually @, ˆX, or ˆU), kills the insert on this line
. repeats the changing command
O opens and inputs new lines, above the current
U undoes the changes you made to the current line
a appends text after the cursor
c changes the object you specify to the following text
d deletes the object you specify
i inserts text before the cursor
o opens and inputs new lines, below the current
u undoes the last change
4. Moving about; rearranging and duplicating text
4.1. Low lev el character motions
Now move the cursor to a line where there is a punctuation or a bracketing character such as a parenthesis or a
comma or period. Try the command fx where x is this character. This command finds the next x character to the
right of the cursor in the current line. Try then hitting a ;, which finds the next instance of the same character. By
using the f command and then a sequence of ;’s you can often get to a particular place in a line much faster than with
a sequence of word motions or SPACEs. There is also a F command, which is like f, but searches backward. The ;
command repeats F also.
When you are operating on the text in a line it is often desirable to deal with the characters up to, but not
including, the first instance of a character. Try dfx for some x now and notice that the x character is deleted. Undo
this with u and then try dtx; the t here stands for to, i.e. delete up to the next x, but not the x. The command T is
the reverse of t.
When working with the text of a single line, an ↑ moves the cursor to the first non-white position on the line,
and a $ moves it to the end of the line. Thus $a will append new text at the end of the current line.
Your file may have tab (ˆI) characters in it. These characters are represented as a number of spaces expanding
to a tab stop, where tab stops are every 8 positions.* When the cursor is at a tab, it sits on the last of the several
spaces which represent that tab. Try moving the cursor back and forth over tabs so you understand how this works.
On rare occasions, your file may have nonprinting characters in it. These characters are displayed in the same
way they are represented in this document, that is with a two character code, the first character of which is ‘ˆ’. On
the screen non-printing characters resemble a ‘ˆ’ character adjacent to another, but spacing or backspacing over the
character will reveal that the two characters are, like the spaces representing a tab character, a single character.
The editor sometimes discards control characters, depending on the character and the setting of the beautify
option, if you attempt to insert them in your file. You can get a control character in the file by beginning an insert
and then typing a ˆV before the control character. The ˆV quotes the following character, causing it to be inserted
directly into the file.
4.2. Higher level text objects
In working with a document it is often advantageous to work in terms of sentences, paragraphs, and sections.
The operations ( and ) move to the beginning of the previous and next sentences respectively. Thus the command d)
will delete the rest of the current sentence; likewise d( will delete the previous sentence if you are at the beginning of
the current sentence, or the current sentence up to where you are if you are not at the beginning of the current
* This is settable by a command of the form :se ts=xCR, where x is 4 to set tabstops every four columns. This has effect on
the screen representation within the editor.
![](https://csdnimg.cn/release/download_crawler_static/11547189/bg9.jpg)
-- --
An Introduction to Display Editing with Vi USD:11-9
sentence.
A sentence is defined to end at a ‘.’, ‘!’ or ‘?’ which is followed by either the end of a line, or by two spaces.
Any number of closing ‘)’, ‘]’, ‘"’ and ‘´’ characters may appear after the ‘.’, ‘!’ or ‘?’ before the spaces or end of
line.
The operations { and } move over paragraphs and the operations [[ and ]] move over sections.†
A paragraph begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs
of characters in the definition of the string valued option paragraphs. The default setting for this option defines the
paragraph macros of the −ms and −mm macro packages, i.e. the ‘.IP’, ‘.LP’, ‘.PP’ and ‘.QP’, ‘.P’ and ‘.LI’ macros.‡
Each paragraph boundary is also a sentence boundary. The sentence and paragraph commands can be given counts
to operate over groups of sentences and paragraphs.
Sections in the editor begin after each macro in the sections option, normally ‘.NH’, ‘.SH’, ‘.H’ and ‘.HU’,
and each line with a formfeed ˆL in the first column. Section boundaries are always line and paragraph boundaries
also.
Try experimenting with the sentence and paragraph commands until you are sure how they work. If you have
a large document, try looking through it using the section commands. The section commands interpret a preceding
count as a different window size in which to redraw the screen at the new location, and this window size is the base
size for newly drawn windows until another size is specified. This is very useful if you are on a slow terminal and
are looking for a particular section. You can give the first section command a small count to then see each succes-
sive section heading in a small window.
4.3. Rearranging and duplicating text
The editor has a single unnamed buffer where the last deleted or changed away text is sav ed, and a set of
named buffers a−z which you can use to save copies of text and to move text around in your file and between files.
The operator y yanks a copy of the object which follows into the unnamed buffer. If preceded by a buffer
name, "x y, where x here is replaced by a letter a−z, it places the text in the named buffer. The text can then be put
back in the file with the commands p and P; p puts the text after or below the cursor, while P puts the text before or
above the cursor.
If the text which you yank forms a part of a line, or is an object such as a sentence which partially spans more
than one line, then when you put the text back, it will be placed after the cursor (or before if you use P). If the
yanked text forms whole lines, they will be put back as whole lines, without changing the current line. In this case,
the put acts much like a o or O command.
Try the command YP. This makes a copy of the current line and leaves you on this copy, which is placed
before the current line. The command Y is a convenient abbreviation for yy. The command Yp will also make a
copy of the current line, and place it after the current line. You can give Y a count of lines to yank, and thus dupli-
cate several lines; try 3YP.
To move text within the buffer, you need to delete it in one place, and put it back in another. You can precede
a delete operation by the name of a buffer in which the text is to be stored as in "a5dd deleting 5 lines into the
named buffer a. You can then move the cursor to the eventual resting place of the these lines and do a "ap or "aP to
put them back. In fact, you can switch and edit another file before you put the lines back, by giving a command of
the form :e nameCR where name is the name of the other file you want to edit. You will have to write back the con-
tents of the current editor buffer (or discard them) if you have made changes before the editor will let you switch to
the other file. An ordinary delete command saves the text in the unnamed buffer, so that an ordinary put can move it
elsewhere. However, the unnamed buffer is lost when you change files, so to move text from one file to another you
should use an unnamed buffer.
† The [[ and ]] operations require the operation character to be doubled because they can move the cursor far from where it
currently is. While it is easy to get back with the command ``, these commands would still be frustrating if they were easy
to hit accidentally.
‡ You can easily change or extend this set of macros by assigning a different string to the paragraphs option in your EX-
INIT. See section 6.2 for details. The ‘.bp’ directive is also considered to start a paragraph.
![](https://csdnimg.cn/release/download_crawler_static/11547189/bga.jpg)
-- --
USD:11-10 An Introduction to Display Editing with Vi
4.4. Summary.
↑ first non-white on line
$ end of line
) forward sentence
} forward paragraph
]] forward section
( backward sentence
{ backward paragraph
[[ backward section
fx find x forward in line
p put text back, after cursor or below current line
y yank operator, for copies and moves
tx up to x forward, for operators
Fx f backward in line
P put text back, before cursor or above current line
Tx t backward in line
5. High level commands
5.1. Writing, quitting, editing new files
So far we have seen how to enter vi and to write out our file using either ZZ or :wCR. The first exits from the
editor, (writing if changes were made), the second writes and stays in the editor.
If you have changed the editor’s copy of the file but do not wish to save your changes, either because you
messed up the file or decided that the changes are not an improvement to the file, then you can give the command
:q!CR to quit from the editor without writing the changes. You can also reedit the same file (starting over) by giving
the command :e!CR. These commands should be used only rarely, and with caution, as it is not possible to recover
the changes you have made after you discard them in this manner.
You can edit a different file without leaving the editor by giving the command :e nameCR. If you have not
written out your file before you try to do this, then the editor will tell you this, and delay editing the other file. You
can then give the command :wCR to save your work and then the :e nameCR command again, or carefully give the
command :e! nameCR, which edits the other file discarding the changes you have made to the current file. To hav e
the editor automatically save changes, include set autowrite in your EXINIT, and use :n instead of :e.
5.2. Escaping to a shell
You can get to a shell to execute a single command by giving a vi command of the form :!cmdCR. The system
will run the single command cmd and when the command finishes, the editor will ask you to hit a RETURN to con-
tinue. When you have finished looking at the output on the screen, you should hit RETURN and the editor will clear
the screen and redraw it. You can then continue editing. You can also give another : command when it asks you for
a RETURN; in this case the screen will not be redrawn.
If you wish to execute more than one command in the shell, then you can give the command :shCR. This will
give you a new shell, and when you finish with the shell, ending it by typing a ˆD, the editor will clear the screen and
continue.
On systems which support it, ˆZ will suspend the editor and return to the (top level) shell. When the editor is
resumed, the screen will be redrawn.
5.3. Marking and returning
The command `` returned to the previous place after a motion of the cursor by a command such as /, ? or G.
You can also mark lines in the file with single letter tags and return to these marks later by naming the tags. Try
marking the current line with the command mx, where you should pick some letter for x, say ‘a’. Then move the
cursor to a different line (any way you like) and hit `a. The cursor will return to the place which you marked.
Marks last only until you edit another file.
剩余45页未读,继续阅读
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://profile-avatar.csdnimg.cn/3a24d63b439b43bead59dd7182f307f3_drjiachen.jpg!1)
drjiachen
- 粉丝: 171
- 资源: 2139
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- Vue实现iOS原生Picker组件:详细解析与实现思路
- Arduino蓝牙小车:参数调试与功能控制
- 百度Java面试精华:200页精选资源涵盖核心知识点
- Swift使用CoreData填坑指南:CoreData在Swift 3.0的变化
- 微距离无线充电器创新设计及其实验探索
- MTK Android平台开发全攻略:44步详解流程
- RecyclerView全面解析:替代ListView的新选择
- Android开发:自动适配中英文键盘解决方案
- Android调用WebService接口教程
- Android开发:BitmapUtil图片处理全解析与实例
- Android多线程断点续传实现详解
- PCA算法在人脸识别会议签到系统中的应用
- EventBus 3.0:Android事件总线详解与实战应用
- Android FileUtil:全面解析文件操作实用技巧与实例
- RecyclerView添加头部和尾部实战教程
- Android实现微博滑动固定顶部栏实战与优化
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)