代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_04 - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ usr_04<br />
<a name="top"></a><h1>usr_04 - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="usr_04.html" name="usr_04.txt">usr_04.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2014 Aug 29<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Making small changes<br>
<br>
<br>
This chapter shows you several ways of making corrections and moving text<br>
around. It teaches you the three basic ways to change text: operator-motion,<br>
Visual mode and text objects.<br>
<br>
<a class="Identifier" href="usr_04.html#04.1">04.1</a> Operators and motions<br>
<a class="Identifier" href="usr_04.html#04.2">04.2</a> Changing text<br>
<a class="Identifier" href="usr_04.html#04.3">04.3</a> Repeating a change<br>
<a class="Identifier" href="usr_04.html#04.4">04.4</a> Visual mode<br>
<a class="Identifier" href="usr_04.html#04.5">04.5</a> Moving text<br>
<a class="Identifier" href="usr_04.html#04.6">04.6</a> Copying text<br>
<a class="Identifier" href="usr_04.html#04.7">04.7</a> Using the clipboard<br>
<a class="Identifier" href="usr_04.html#04.8">04.8</a> Text objects<br>
<a class="Identifier" href="usr_04.html#04.9">04.9</a> Replace mode<br>
<a class="Identifier" href="usr_04.html#04.10">04.10</a> Conclusion<br>
<br>
Next chapter: <a class="Identifier" href="usr_05.html">usr_05.txt</a> Set your settings<br>
Previous chapter: <a class="Identifier" href="usr_03.html">usr_03.txt</a> Moving around<br>
Table of contents: <a class="Identifier" href="usr_toc.html">usr_toc.txt</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.1" name="04.1">04.1</a> Operators and motions<br>
<br>
In chapter 2 you learned the "x" command to delete a single character. And<br>
using a count: "4x" deletes four characters.<br>
The "dw" command deletes a word. You may recognize the "w" command as the<br>
move word command. In fact, the "d" command may be followed by any motion<br>
command, and it deletes from the current location to the place where the<br>
cursor winds up.<br>
The "4w" command, for example, moves the cursor over four words. The d4w<br>
command deletes four words.<br>
<br>
<span class="PreProc">To err is human. To really foul up you need a computer.</span><br>
------------------><br>
d4w<br>
<br>
<span class="PreProc">To err is human. you need a computer.</span><br>
<br>
Vim only deletes up to the position where the motion takes the cursor. That's<br>
because Vim knows that you probably don't want to delete the first character<br>
of a word. If you use the "e" command to move to the end of a word, Vim<br>
guesses that you do want to include that last character:<br>
<br>
<span class="PreProc">To err is human. you need a computer.</span><br>
--------><br>
d2e<br>
<br>
<span class="PreProc">To err is human. a computer.</span><br>
<br>
Whether the character under the cursor is included depends on the command you<br>
used to move to that character. The reference manual calls this "exclusive"<br>
when the character isn't included and "inclusive" when it is.<br>
<br>
The "$" command moves to the end of a line. The "d$" command deletes from the<br>
cursor to the end of the line. This is an inclusive motion, thus the last<br>
character of the line is included in the delete operation:<br>
<br>
<span class="PreProc">To err is human. a computer.</span><br>
------------><br>
d$<br>
<br>
<span class="PreProc">To err is human</span><br>
<br>
There is a pattern here: operator-motion. You first type an operator command.<br>
For example, "d" is the delete operator. Then you type a motion command like<br>
"4l" or "w". This way you can operate on any text you can move over.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.2" name="04.2">04.2</a> Changing text<br>
<br>
Another operator is "c", change. It acts just like the "d" operator, except<br>
it leaves you in Insert mode. For example, "cw" changes a word. Or more<br>
specifically, it deletes a word and then puts you in Insert mode.<br>
<br>
<span class="PreProc">To err is human</span><br>
-------><br>
c2wbe<span class="Special"><Esc></span><br>
<br>
<span class="PreProc">To be human</span><br>
<br>
This "c2wbe<span class="Special"><Esc></span>" contains these bits:<br>
<br>
c the change operator<br>
2w move two words (they are deleted and Insert mode started)<br>
be insert this text<br>
<span class="Special"><Esc></span> back to Normal mode<br>
<br>
If you have paid attention, you will have noticed something strange: The space<br>
before "human" isn't deleted. There is a saying that for every problem there<br>
is an answer that is simple, clear, and wrong. That is the case with the<br>
example used here for the "cw" command. The c operator works just like the<br>
d operator, with one exception: "cw". It actually works like "ce", change to<br>
end of word. Thus the space after the word isn't included. This is an<br>
exception that dates back to the old Vi. Since many people are used to it<br>
now, the inconsistency has remained in Vim.<br>
<br>
<br>
MORE CHANGES<br>
<br>
Like "dd" deletes a whole line, "cc" changes a whole line. It keeps the<br>
existing indent (leading white space) though.<br>
<br>
Just like "d$" deletes until the end of the line, "c$" changes until the end<br>
of the line. It's like doing "d$" to delete the text and then "a" to start<br>
Insert mode and append new text.<br>
<br>
<br>
SHORTCUTS<br>
<br>
Some operator-motion commands are used so often that they have been given a<br>
single letter command:<br>
<br>
x stands for dl (delete character under the cursor)<br>
X stands for dh (delete character left of the cursor)<br>
D stands for d$ (delete to end of the line)<br>
C stands for c$ (change to end of the line)<br>
s stands for cl (change one character)<br>
S stands for cc (change a whole line)<br>
<br>
<br>
WHERE TO PUT THE COUNT<br>
<br>
The commands "3dw" and "d3w" delete three words. If you want to get really<br>
picky about things, the first command, "3dw", deletes one word three times;<br>
the command "d3w" deletes three words once. This is a difference without a<br>
distinction. You can actually put in two counts, however. For example,<br>
"3d2w" deletes two words, repeated three times, for a total of six words.<br>
<br>
<br>
REPLACING WITH ONE CHARACTER<br>
<br>
The "r" command is not an operator. It waits for you to type a character, and<br>
will replace the character under the cursor with it. You could do the same<br>
with "cl" or with the "s" command, but with "r" you don't have to press <span class="Special"><Esc></span><br>
<br>
<span class="PreProc">there is somerhing grong here</span><br>
rT rt rw<br>
<br>
<span class="PreProc">There is something wrong here</span><br>
<br>
Using a count with "r" causes that many characters to be replaced with the<br>
same character. Example:<br>
<br>
<span class="PreProc">There is something wrong here</span><br>
5rx<br>
<br>
<span class="PreProc">There is something xxxxx here</span><br>
<br>
To replace a character with a line break use "r<span class="Special"><Enter></span>". This deletes one<br>
character and inserts a line break. Using a count here only applies to the<br>
number of characters deleted: "4r<span class="Special"><Enter></span>" replaces four characters with one<br>
line break.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.3" name="04.3">04.3</a> Repeating a change<br>
<br>
The "." command is one of the most simple yet powerful commands in Vim. It<br>
repeats the last change. For instance, suppose you are editing an HTML file<br>
and want to delete all the <span class="Special"><B></span> tags. You position the cursor on the first <<br>
and delete the <span class="Special"><B></span> with the command "df>". You then go to the < of the next<br>
</B> and kill it using the "." command. The "." command executes the last<br>
change command (in this case, "df>"). To delete another tag, position the<br>
cursor on the < and use the "." command.<br>
<br>
<span class="PreProc">To <B>generate</B> a table of <B>contents</span><br>
f< find first < ---><br>
df> delete to > --><br>
f< find next < ---------><br>
. repeat df> ---><br>
f< find next < -------------><br>
. repeat df> --><br>
<br>
The "." command works for all changes you make, except for the "u" (undo),<br>
<span class="Special">CTRL-R</span> (redo) and commands that start with a colon (:).<br>
<br>
Another example: You want to change the word "four" to "five". It appears<br>
several times in your text. You can do this quickly with this sequence of<br>
commands:<br>
<br>
/four<span class="Special"><Enter></span> find the first string "four"<br>
cwfive<span class="Special"><Esc></span> change the word to "five"<br>
n find the next "four"<br>
. repeat the change to "five"<br>
n find the next "four"<br>
. repeat the change<br>
etc.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.4" name="04.4">04.4</a> Visual mode<br>
<br>
To delete simple items the operator-motion changes work quite well. But often<br>
it's not so easy to decide which command will move over the text you want to<br>
change. Then you can use Visual mode.<br>
<br>
You start Visual mode by pressing "v". You move the cursor over the text you<br>
want to work on. While you do this, the text is highlighted. Finally type<br>
the operator command.<br>
For example, to delete from halfway one word to halfway another word:<br>
<br>
<span class="PreProc">This is an examination sample of visual mode</span><br>
----------><br>
velllld<br>
<br>
<span class="PreProc">This is an example of visual mode</span><br>
<br>
When doing this you don't really have to count how many times you have to<br>
press "l" to end up in the right position. You can immediately see what text<br>
will be deleted when you press "d".<br>
<br>
If at any time you decide you don't want to do anything with the highlighted<br>
text, just press <span class="Special"><Esc></span> and Visual mode will stop without doing anything.<br>
<br>
<br>
SELECTING LINES<br>
<br>
If you want to work on whole lines, use "V" to start Visual mode. You will<br>
see right away that the whole line is highlighted, without moving around.<br>
When you move left or right nothing changes. When you move up or down the<br>
selection is extended whole lines at a time.<br>
For example, select three lines with "Vjj":<br>
<br>
+------------------------+<br>
| text more text |<br>
>> | more text more text | |<br>
selected lines >> | text text text | | Vjj<br>
>> | text more | V<br>
| more text more |<br>
+------------------------+<br>
<br>
<br>
SELECTING BLOCKS<br>
<br>
If you want to work on a rectangular block of characters, use <span class="Special">CTRL-V</span> to start<br>
Visual mode. This is very useful when working on tables.<br>
<br>
name Q1 Q2 Q3<br>
pierre 123 455 234<br>
john 0 90 39<br>
steve 392 63 334<br>
<br>
To delete the middle "Q2" column, move the cursor to the "Q" of "Q2". Press<br>
<span class="Special">CTRL-V</span> to start blockwise Visual mode. Now move the cursor three lines down<br>
with "3j" and to the next word with "w". You can see the first character of<br>
the last column is included. To exclude it, use "h". Now press "d" and the<br>
middle column is gone.<br>
<br>
<br>
GOING TO THE OTHER SIDE<br>
<br>
If you have selected some text in Visual mode, and discover that you need to<br>
change the other end of the selection, use the "o" command (Hint: o for other<br>
end). The cursor will go to the other end, and you can move the cursor to<br>
change where the selection starts. Pressing "o" again brings you back to the<br>
other end.<br>
<br>
When using blockwise selection, you have four corners. "o" only takes you to<br>
one of the other corners, diagonally. Use "O" to move to the other corner in<br>
the same line.<br>
<br>
<span class="Todo">Note</span> that "o" and "O" in Visual mode work very differently from Normal mode,<br>
where they open a new line below or above the cursor.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.5" name="04.5">04.5</a> Moving text<br>
<br>
When you delete something with the "d", "x", or another command, the text is<br>
saved. You can paste it back by using the p command. (The Vim name for<br>
this is put).<br>
Take a look at how this works. First you will delete an entire line, by<br>
putting the cursor on the line you want to delete and typing "dd". Now you<br>
move the cursor to where you want to put the line and use the "p" (put)<br>
command. The line is inserted on the line below the cursor.<br>
<br>
a line a line a line<br>
line 2 dd line 3 p line 3<br>
line 3 line 2<br>
<br>
Because you deleted an entire line, the "p" command placed the text line below<br>
the cursor. If you delete part of a line (a word, for instance), the "p"<br>
command puts it just after the cursor.<br>
<br>
<span class="PreProc">Some more boring try text to out commands.</span><br>
----><br>
dw<br>
<br>
<span class="PreProc">Some more boring text to out commands.</span><br>
-------><br>
welp<br>
<br>
<span class="PreProc">Some more boring text to try out commands.</span><br>
<br>
<br>
MORE ON PUTTING<br>
<br>
The "P" command puts text like "p", but before the cursor. When you deleted a<br>
whole line with "dd", "P" will put it back above the cursor. When you deleted<br>
a word with "dw", "P" will put it back just before the cursor.<br>
<br>
You can repeat putting as many times as you like. The same text will be used.<br>
<br>
You can use a count with "p" and "P". The text will be repeated as many times<br>
as specified with the count. Thus "dd" and then "3p" puts three copies of the<br>
same deleted line.<br>
<br>
<br>
SWAPPING TWO CHARACTERS<br>
<br>
Frequently when you are typing, your fingers get ahead of your brain (or the<br>
other way around?). The result is a typo such as "teh" for "the". Vim<br>
makes it easy to correct such problems. Just put the cursor on the e of "teh"<br>
and execute the command "xp". This works as follows: "x" deletes the<br>
character e and places it in a register. "p" puts the text after the cursor,<br>
which is after the h.<br>
<br>
<span class="PreProc">teh th the</span><br>
x p<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.6" name="04.6">04.6</a> Copying text<br>
<br>
To copy text from one place to another, you could delete it, use "u" to undo<br>
the deletion and then "p" to put it somewhere else. There is an easier way:<br>
yanking. The "y" operator copies text into a register. Then a "p" command<br>
can be used to put it.<br>
Yanking is just a Vim name for copying. The "c" letter was already used<br>
for the change operator, and "y" was still available. Calling this<br>
operator "yank" made it easier to remember to use the "y" key.<br>
<br>
Since "y" is an operator, you use "yw" to yank a word. A count is possible as<br>
usual. To yank two words use "y2w". Example:<br>
<br>
<span class="PreProc">let sqr = LongVariable *</span><br>
--------------><br>
y2w<br>
<br>
<span class="PreProc">let sqr = LongVariable *</span><br>
p<br>
<br>
<span class="PreProc">let sqr = LongVariable * LongVariable</span><br>
<br>
Notice that "yw" includes the white space after a word. If you don't want<br>
this, use "ye".<br>
<br>
The "yy" command yanks a whole line, just like "dd" deletes a whole line.<br>
Unexpectedly, while "D" deletes from the cursor to the end of the line, "Y"<br>
works like "yy", it yanks the whole line. Watch out for this inconsistency!<br>
Use "y$" to yank to the end of the line.<br>
<br>
a text line yy a text line a text line<br>
line 2 line 2 p line 2<br>
last line last line a text line<br>
last line<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.7" name="04.7">04.7</a> Using the clipboard<br>
<br>
If you are using the GUI version of Vim (gvim), you can find the "Copy" item<br>
in the "Edit" menu. First select some text with Visual mode, then use the<br>
Edit/Copy menu. The selected text is now copied to the clipboard. You can<br>
paste the text in other programs. In Vim itself too.<br>
<br>
If you have copied text to the clipboard in another application, you can paste<br>
it in Vim with the Edit/Paste menu. This works in Normal mode and Insert<br>
mode. In Visual mode the selected text is replaced with the pasted text.<br>
<br>
The "Cut" menu item deletes the text before it's put on the clipboard. The<br>
"Copy", "Cut" and "Paste" items are also available in the popup menu (only<br>
when there is a popup menu, of course). If your Vim has a toolbar, you can<br>
also find these items there.<br>
<br>
If you are not using the GUI, or if you don't like using a menu, you have to<br>
use another way. You use the normal "y" (yank) and "p" (put) commands, but<br>
prepend "* (double-quote star) before it. To copy a line to the clipboard:<br>
<br>
<div class="helpExample"> "*yy</div>
<br>
To put text from the clipboard back into the text:<br>
<br>
<div class="helpExample"> "*p</div>
<br>
This only works on versions of Vim that include clipboard support. More about<br>
the clipboard in section <a class="Identifier" href="usr_09.html#09.3">09.3</a> and here: <a class="Identifier" href="gui.html#clipboard">clipboard</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.8" name="04.8">04.8</a> Text objects<br>
<br>
If the cursor is in the middle of a word and you want to delete that word, you<br>
need to move back to its start before you can do "dw". There is a simpler way<br>
to do this: "daw".<br>
<br>
<span class="PreProc">this is some example text.</span><br>
daw<br>
<br>
<span class="PreProc">this is some text.</span><br>
<br>
The "d" of "daw" is the delete operator. "aw" is a text object. Hint: "aw"<br>
stands for "A Word". Thus "daw" is "Delete A Word". To be precise, the white<br>
space after the word is also deleted (the white space before the word at the<br>
end of the line).<br>
<br>
Using text objects is the third way to make changes in Vim. We already had<br>
operator-motion and Visual mode. Now we add operator-text object.<br>
It is very similar to operator-motion, but instead of operating on the text<br>
between the cursor position before and after a movement command, the text<br>
object is used as a whole. It doesn't matter where in the object the cursor<br>
was.<br>
<br>
To change a whole sentence use "cis". Take this text:<br>
<br>
<span class="PreProc">Hello there. This</span><br>
<span class="PreProc">is an example. Just</span><br>
<span class="PreProc">some text.</span><br>
<br>
Move to the start of the second line, on "is an". Now use "cis":<br>
<br>
<span class="PreProc">Hello there. Just</span><br>
<span class="PreProc">some text.</span><br>
<br>
The cursor is in between the blanks in the first line. Now you type the new<br>
sentence "Another line.":<br>
<br>
<span class="PreProc">Hello there. Another line. Just</span><br>
<span class="PreProc">some text.</span><br>
<br>
"cis" consists of the "c" (change) operator and the "is" text object. This<br>
stands for "Inner Sentence". There is also the "as" (a sentence) object. The<br>
difference is that "as" includes the white space after the sentence and "is"<br>
doesn't. If you would delete a sentence, you want to delete the white space<br>
at the same time, thus use "das". If you want to type new text the white<br>
space can remain, thus you use "cis".<br>
<br>
You can also use text objects in Visual mode. It will include the text object<br>
in the Visual selection. Visual mode continues, thus you can do this several<br>
times. For example, start Visual mode with "v" and select a sentence with<br>
"as". Now you can repeat "as" to include more sentences. Finally you use an<br>
operator to do something with the selected sentences.<br>
<br>
You can find a long list of text objects here: <a class="Identifier" href="motion.html#text-objects">text-objects</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.9" name="04.9">04.9</a> Replace mode<br>
<br>
The "R" command causes Vim to enter replace mode. In this mode, each<br>
character you type replaces the one under the cursor. This continues until<br>
you type <span class="Special"><Esc></span>.<br>
In this example you start Replace mode on the first "t" of "text":<br>
<br>
<span class="PreProc">This is text.</span><br>
Rinteresting.<span class="Special"><Esc></span><br>
<br>
<span class="PreProc">This is interesting.</span><br>
<br>
You may have noticed that this command replaced 5 characters in the line with<br>
twelve others. The "R" command automatically extends the line if it runs out<br>
of characters to replace. It will not continue on the next line.<br>
<br>
You can switch between Insert mode and Replace mode with the <span class="Special"><Insert></span> key.<br>
<br>
When you use <span class="Special"><BS></span> (backspace) to make correction, you will notice that the<br>
old text is put back. Thus it works like an undo command for the last typed<br>
character.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_04.html#04.10" name="04.10">04.10</a> Conclusion<br>
<br>
The operators, movement commands and text objects give you the possibility to<br>
make lots of combinations. Now that you know how it works, you can use <span class="Special">N</span><br>
operators with M movement commands to make <span class="Special">N</span> * M commands!<br>
<br>
You can find a list of operators here: <a class="Identifier" href="motion.html#operator">operator</a><br>
<br>
For example, there are many other ways to delete pieces of text. Here are a<br>
few often used ones:<br>
<br>
x delete character under the cursor (short for "dl")<br>
X delete character before the cursor (short for "dh")<br>
D delete from cursor to end of line (short for "d$")<br>
dw delete from cursor to next start of word<br>
db delete from cursor to previous start of word<br>
diw delete word under the cursor (excluding white space)<br>
daw delete word under the cursor (including white space)<br>
dG delete until the end of the file<br>
dgg delete until the start of the file<br>
<br>
If you use "c" instead of "d" they become change commands. And with "y" you<br>
yank the text. And so forth.<br>
<br>
<br>
There are a few often used commands to make changes that didn't fit somewhere<br>
else:<br>
<br>
~ change case of the character under the cursor, and move the<br>
cursor to the next character. This is not an operator (unless<br>
<a class="Type" href="options.html#'tildeop'">'tildeop'</a> is set), thus you can't use it with a motion<br>
command. It does work in Visual mode and changes case for<br>
all the selected text then.<br>
<br>
I Start Insert mode after moving the cursor to the first<br>
non-blank in the line.<br>
<br>
A Start Insert mode after moving the cursor to the end of the<br>
line.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_05.html">usr_05.txt</a> Set your settings<br>
<br>
Copyright: see <a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a> vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。