⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rhl16.htm

📁 linux的初学电子书
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<BR>

<BR>

<PRE>

<FONT COLOR="#000080">/[a-z]y</FONT></PRE>

<P>This command used in asong will find the strings &quot;by&quot; and &quot;my,&quot; as well as any word with these strings inside them (such as &quot;bay&quot;). This works because the range of characters given are treated as an enumerated range of 
ASCII values. Thus, you could also include a range of numbers (for example, 0-9). Now try the following command:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">/[Mm]y</FONT></PRE>

<P>This will locate the strings &quot;My&quot; and &quot;my.&quot;

<BR>

<P>In vi, searches without regular expressions will find only exact matches of the supplied pattern (including the case of the letters in the pattern). Clearly, regular expressions can be used to enhance many types of searches in which you may not know 
exactly how a pattern appears in a file.

<BR>

<P>One of the more common applications of a search is to replace instances of one word (or pattern) with another. This is done with an ex command that starts with a colon. To search the entire asong file for the string &quot;Down&quot; and replace it with 
the string &quot;Up,&quot; type

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">:%s/Down/Up/g</FONT></PRE>

<P>The s indicates that this is a search operation, the % means that the entire file is to be searched, &quot;Down&quot; is the pattern to be found, &quot;Up&quot; is the new pattern, and the g tells vi that the search should continue until there are no 
more pattern matches. Without the g, vi would perform the replacement on only the first match it finds. This command also works with regular expressions appearing in the search pattern and the replacement pattern.

<BR>

<BR>

<A NAME="E69E222"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Setting Preferences</B></FONT></CENTER></H4>

<BR>

<P>vi is configurable, which means that you can set options to control your editing environment. These options are initialized with default values that you can modify in vi at any time. vi is configured using the set command. The set command must be 
preceded by a colon and entered by pressing Return. For example, to display line numbers in the editor, you would issue

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">:set number</FONT></PRE>

<P>The following table describes a few of the more common set commands.

<BR>



<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

all

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Displays a list of all available set options and their current status.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

errorbells

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Sounds the terminal bell when an error occurs.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

ignorecase

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Searches are case-insensitive.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

number

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Displays line numbers in the leftmost column of the screen (these are not written to the file).</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

showmode

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

An indication appears at the bottom right of the screen if you are in input mode, change mode, replace mode, and so on.</FONT>

</TABLE><P>set commands that do not take a value can be switched off by inserting a &quot;no&quot; as a prefix to the set parameter. For example, the command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">:set nonumber</FONT></PRE>

<P>switches line numbering off. The command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">:set</FONT></PRE>

<P>shows only the options that you have changed.

<BR>

<P>The settings that you use in a vi session are (unfortunately) lost each time you exit vi. If you do not like the idea of resetting these options each time you use vi, there is an easier way to perform this initialization. Use the vi initialization file 
called .exrc. vi searches for this file in your home directory each time it is invoked. If it can't find this file, it uses the defaults set within the vi program. As you will see in the following example, the .exrc file can also be used to define vi 
macros.

<BR>

<P>A sample .exrc file would look something like this:

<BR>

<PRE>

<FONT COLOR="#000080">set number

set errorbells

set showmode</FONT></PRE>

<P>Note that the colon is not required before a set command in a .exrc file.

<BR>

<BR>

<A NAME="E69E223"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>A Summary of Commands</B></FONT></CENTER></H4>

<BR>

<P>The following is a summary of the more essential commands described in this chapter. You should consult the vi man page for more details on the many other vi commands.

<BR>



<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

i

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Starts inserting text at the cursor.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

h

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor one character to the left.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

j

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor down one line.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

k

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor up one line.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

l

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor one character to the right.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-f

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Scrolls forward one screen.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-b

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Scrolls backward one screen.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

ndd

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Deletes the next n lines.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

nyy

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Yanks the next n lines into the unnamed buffer.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

p

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Puts the contents of the unnamed buffer to the right of the cursor.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

u

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Undoes the last change.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

:wq

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Writes changes and exits vi.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

:q!

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Exits vi without saving changes.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

:set all

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Shows all set parameters and their values.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

/string

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Searches forward for string.</FONT>

</TABLE><BR>

<A NAME="E68E117"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>The emacs Editor</B></FONT></CENTER></H3>

<BR>

<P>emacs has become the editor of choice for many users because of its online help facility and its extensive collection of editing commands. For programmers, emacs is especially attractive because it can be configured to format source code for a variety 
of languages such as C, C++, and Lisp. emacs is somewhat easier to learn than vi, but it also features a much larger set of commands.

<BR>

<BR>

<A NAME="E69E224"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Starting emacs</B></FONT></CENTER></H4>

<BR>

<P>emacs is invoked from the command line by entering

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">emacs</FONT></PRE>

<P>To start emacs with a file to be edited, enter

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">emacs filename</FONT></PRE>

<P>If you start emacs with a file, the screen will display the contents starting from the first line. Note the two lines at the bottom of the screen. The first of these lines, known as the mode line, displays the name of the file being edited and which 
part of the file that you are looking at (for example, TOP, 20%, BOT). The last line on the screen is the echo line, which emacs uses to display system messages and as a prompt for more input.

<BR>

<BR>

<A NAME="E69E225"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Control and Meta Keys</B></FONT></CENTER></H4>

<BR>

<P>You are quite free at this point to start entering text into the edit buffer at the cursor location. However, you're probably wondering, &quot;How do I move the cursor around?&quot; Before I fill you in on this little detail, there are two keys that you 
should know about: the Control key (which I will refer to as C) and the Meta key (denoted by M). The Control key is used in most of the commands for emacs, but some use the Meta key instead. Commands in emacs consist of combinations of the Control or Meta 
key followed by some other character. It is necessary to hold down the Control key when pressing the next character, whereas the Meta key can be pressed and released before you enter the next character. For the PC, the Meta key is usually the Alt key.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>You may see the Control key abbreviated as C and the Meta key denoted by M.

<BR>On the PC, you should use the Alt key for the Meta key.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E226"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Moving the Cursor</B></FONT></CENTER></H4>

<BR>

<P>Now that you know about the Control key, we can talk about the cursor-movement commands. The basic ones that you need to remember are:

<BR>



<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-f

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor forward one character.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-b

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor back one character.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-p

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Moves the cursor to the previous line.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

C-n

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -