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

📄 ch31_08.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 31] 31.8 More Examples of Mapping Keys in vi </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:46:18Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch31_01.htm"TITLE="31. Creating Custom Commands in vi"><LINKREL="prev"HREF="ch31_07.htm"TITLE="31.7 Maps for Repeated Edits "><LINKREL="next"HREF="ch31_09.htm"TITLE="31.9 Good Stuff for Your .exrc File "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_07.htm"TITLE="31.7 Maps for Repeated Edits "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 31.7 Maps for Repeated Edits "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 31<BR>Creating Custom Commands in vi</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_09.htm"TITLE="31.9 Good Stuff for Your .exrc File "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 31.9 Good Stuff for Your .exrc File "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-6390">31.8 More Examples of Mapping Keys in vi </A></H2><PCLASS="para">The examples that follow will give you an idea of the clevershortcuts possible when defining keyboard maps.</P><OLCLASS="orderedlist"><LICLASS="listitem"><PCLASS="para">Add text whenever you move to the end of a word:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">map e ea</PRE></BLOCKQUOTE></P><PCLASS="para">Most of the time, the only reason you want to move to the end ofa word is to add text. This map sequence puts you in text-input modeautomatically.Note that the mapped key, <CODECLASS="literal">e</CODE>, has meaning in <EMCLASS="emphasis">vi</EM>.You're allowed to map a key that is already used by <EMCLASS="emphasis">vi</EM>,but the key's normal function will be unavailable as longas the map is in effect. This isn't so bad in this case, sincethe <CODECLASS="literal">E</CODE> command is often identical to <CODECLASS="literal">e</CODE>.</P><PCLASS="para">In the remaining examples, we assume that <CODECLASS="literal">e</CODE> has been mapped to <CODECLASS="literal">ea</CODE>.&#13;</P></LI><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link">Save a file and edit the next one in a series (<ACLASS="linkend"HREF="ch30_04.htm"TITLE="Editing Multiple Files with vi ">30.4</A>)</SPAN>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">map q :w^M:n^M</PRE></BLOCKQUOTE></P><PCLASS="para">Notice that you can map keys to <EMCLASS="emphasis">ex</EM> commands, but be sureto finish each <EMCLASS="emphasis">ex</EM> command with a RETURN.This sequence makes it easy to move from one file to the nextand is useful when you've opened many short files with one <EMCLASS="emphasis">vi</EM>command.Mapping the letter <CODECLASS="literal">q</CODE> helps youremember that the sequence is similar to a &quot;quit.&quot;</P></LI><LICLASS="listitem"><PCLASS="para">Put <EMCLASS="emphasis">troff</EM> emboldening codes (<EMCLASS="emphasis">\fB</EM> and <EMCLASS="emphasis">\fP</EM>) around a word: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">map v i\fB^[e\fP^[</PRE></BLOCKQUOTE></P><PCLASS="para">This sequence assumes that the cursor is at the beginning of theword. First, you enter text-input mode, then you type the code forbold font. (In <EMCLASS="emphasis">map</EM> commands, you don't need to type two backslashes to produce one backslash.) Next, you return to command modeby typing a<SPANCLASS="link">&quot;quoted&quot; (<ACLASS="linkend"HREF="ch31_06.htm"TITLE="Protecting Keys from Interpretation by ex ">31.6</A>)</SPAN>ESC.Finally, you append the closing <EMCLASS="emphasis">troff</EM> code at the end of the word, and you return to command mode.Of course, the map is not limited to <EMCLASS="emphasis">troff</EM> font codes.You can use it to enclose a word in parentheses or C commentcharacters, to name just a few applications.</P><PCLASS="para">This example shows you that map sequences are allowed to contain other map commands (the <CODECLASS="literal">e</CODE> is already mapped to <CODECLASS="literal">ea</CODE>).The ability to use nested map sequences iscontrolled by <EMCLASS="emphasis">vi</EM>'s<SPANCLASS="link"><CODECLASS="literal">remap</CODE> option (<ACLASS="linkend"HREF="ch31_14.htm"TITLE="Don't Lose Important Functions with vi Maps: Use noremap">31.14</A>)</SPAN>,which is normallyenabled.</P></LI><LICLASS="listitem"><PCLASS="para">Put <EMCLASS="emphasis">troff</EM> emboldening codes around a word, even when thecursor is not at the beginning of the word:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">map V lbi\fB^[e\fP^[</PRE></BLOCKQUOTE></P><PCLASS="para">This sequence is the same as the previous one, except that ituses <CODECLASS="literal">lb</CODE> tohandle the additional task of positioning the cursor at thebeginning of the word. The cursor might be in the middle of theword, so you want to move to the beginning with the <CODECLASS="literal">b</CODE> command.</P><PCLASS="para">But if the cursor were already at the beginning of theword, the <CODECLASS="literal">b</CODE> command would move the cursor to the previousword instead. To guard against that case,type an <CODECLASS="literal">l</CODE> before moving back with <CODECLASS="literal">b</CODE>, so that the cursor never starts on the first letter of the word.You can define variations of this sequence by replacing the <CODECLASS="literal">b</CODE> with <CODECLASS="literal">B</CODE> and the <CODECLASS="literal">e</CODE> with <CODECLASS="literal">Ea</CODE>.In all cases though, the <CODECLASS="literal">l</CODE> command prevents this sequencefrom working if the cursor is at the end of a line.(To get around this, you could add a space to the end of the wordbefore typing the keymap.)</P></LI></OL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">DG</SPAN> <SPANCLASS="bibliomisc">from O'Reilly &amp; Associates' <CITECLASS="citetitle">Learning the vi Editor</CITE>, Chapter 7</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_07.htm"TITLE="31.7 Maps for Repeated Edits "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 31.7 Maps for Repeated Edits "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch31_09.htm"TITLE="31.9 Good Stuff for Your .exrc File "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 31.9 Good Stuff for Your .exrc File "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">31.7 Maps for Repeated Edits </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">31.9 Good Stuff for Your .exrc File </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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