代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_25 - 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_25<br />
<a name="top"></a><h1>usr_25 - 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_25.html" name="usr_25.txt">usr_25.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2016 Mar 28<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Editing formatted text<br>
<br>
<br>
Text hardly ever comes in one sentence per line. This chapter is about<br>
breaking sentences to make them fit on a page and other formatting.<br>
Vim also has useful features for editing single-line paragraphs and tables.<br>
<br>
<a class="Identifier" href="usr_25.html#25.1">25.1</a> Breaking lines<br>
<a class="Identifier" href="usr_25.html#25.2">25.2</a> Aligning text<br>
<a class="Identifier" href="usr_25.html#25.3">25.3</a> Indents and tabs<br>
<a class="Identifier" href="usr_25.html#25.4">25.4</a> Dealing with long lines<br>
<a class="Identifier" href="usr_25.html#25.5">25.5</a> Editing tables<br>
<br>
Next chapter: <a class="Identifier" href="usr_26.html">usr_26.txt</a> Repeating<br>
Previous chapter: <a class="Identifier" href="usr_24.html">usr_24.txt</a> Inserting quickly<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_25.html#25.1" name="25.1">25.1</a> Breaking lines<br>
<br>
Vim has a number of functions that make dealing with text easier. By default,<br>
the editor does not perform automatic line breaks. In other words, you have<br>
to press <span class="Special"><Enter></span> yourself. This is useful when you are writing programs where<br>
you want to decide where the line ends. It is not so good when you are<br>
creating documentation and want the text to be at most 70 character wide.<br>
If you set the <a class="Type" href="options.html#'textwidth'">'textwidth'</a> option, Vim automatically inserts line breaks.<br>
Suppose, for example, that you want a very narrow column of only 30<br>
characters. You need to execute the following command:<br>
<br>
<div class="helpExample"> :set textwidth=30</div>
<br>
Now you start typing (ruler added):<br>
<br>
1 2 3<br>
12345678901234567890123456789012345<br>
<span class="PreProc">I taught programming for a whi</span><br>
<br>
If you type "l" next, this makes the line longer than the 30-character limit.<br>
When Vim sees this, it inserts a line break and you get the following:<br>
<br>
1 2 3<br>
12345678901234567890123456789012345<br>
<span class="PreProc">I taught programming for a</span><br>
<span class="PreProc">whil</span><br>
<br>
Continuing on, you can type in the rest of the paragraph:<br>
<br>
1 2 3<br>
12345678901234567890123456789012345<br>
<span class="PreProc">I taught programming for a</span><br>
<span class="PreProc">while. One time, I was stopped</span><br>
<span class="PreProc">by the Fort Worth police,</span><br>
<span class="PreProc">because my homework was too</span><br>
<span class="PreProc">hard. True story.</span><br>
<br>
You do not have to type newlines; Vim puts them in automatically.<br>
<br>
<span class="Todo">Note</span>:<br>
The <a class="Type" href="options.html#'wrap'">'wrap'</a> option makes Vim display lines with a line break, but this<br>
doesn't insert a line break in the file.<br>
<br>
<br>
REFORMATTING<br>
<br>
The Vim editor is not a word processor. In a word processor, if you delete<br>
something at the beginning of the paragraph, the line breaks are reworked. In<br>
Vim they are not; so if you delete the word "programming" from the first line,<br>
all you get is a short line:<br>
<br>
1 2 3<br>
12345678901234567890123456789012345<br>
<span class="PreProc">I taught for a</span><br>
<span class="PreProc">while. One time, I was stopped</span><br>
<span class="PreProc">by the Fort Worth police,</span><br>
<span class="PreProc">because my homework was too</span><br>
<span class="PreProc">hard. True story.</span><br>
<br>
This does not look good. To get the paragraph into shape you use the "gq"<br>
operator.<br>
Let's first use this with a Visual selection. Starting from the first<br>
line, type:<br>
<br>
<div class="helpExample"> v4jgq</div>
<br>
"v" to start Visual mode, "4j" to move to the end of the paragraph and then<br>
the "gq" operator. The result is:<br>
<br>
1 2 3<br>
12345678901234567890123456789012345<br>
<span class="PreProc">I taught for a while. One</span><br>
<span class="PreProc">time, I was stopped by the</span><br>
<span class="PreProc">Fort Worth police, because my</span><br>
<span class="PreProc">homework was too hard. True</span><br>
<span class="PreProc">story.</span><br>
<br>
<span class="Todo">Note</span>: there is a way to do automatic formatting for specific types of text<br>
layouts, see <a class="Identifier" href="change.html#auto-format">auto-format</a>.<br>
<br>
Since "gq" is an operator, you can use one of the three ways to select the<br>
text it works on: With Visual mode, with a movement and with a text object.<br>
The example above could also be done with "gq4j". That's less typing, but<br>
you have to know the line count. A more useful motion command is "}". This<br>
moves to the end of a paragraph. Thus "gq}" formats from the cursor to the<br>
end of the current paragraph.<br>
A very useful text object to use with "gq" is the paragraph. Try this:<br>
<br>
<div class="helpExample"> gqap</div>
<br>
"ap" stands for "a-paragraph". This formats the text of one paragraph<br>
(separated by empty lines). Also the part before the cursor.<br>
If you have your paragraphs separated by empty lines, you can format the<br>
whole file by typing this:<br>
<br>
<div class="helpExample"> gggqG</div>
<br>
"gg" to move to the first line, "gqG" to format until the last line.<br>
Warning: If your paragraphs are not properly separated, they will be joined<br>
together. A common mistake is to have a line with a space or tab. That's a<br>
blank line, but not an empty line.<br>
<br>
Vim is able to format more than just plain text. See <a class="Identifier" href="change.html#fo-table">fo-table</a> for how to<br>
change this. See the <a class="Type" href="options.html#'joinspaces'">'joinspaces'</a> option to change the number of spaces used<br>
after a full stop.<br>
It is possible to use an external program for formatting. This is useful<br>
if your text can't be properly formatted with Vim's builtin command. See the<br>
<a class="Type" href="options.html#'formatprg'">'formatprg'</a> option.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_25.html#25.2" name="25.2">25.2</a> Aligning text<br>
<br>
To center a range of lines, use the following command:<br>
<br>
<div class="helpExample"> :{range}center [width]</div>
<br>
<span class="Special">{range}</span> is the usual command-line range. <span class="Special">[width]</span> is an optional line width to<br>
use for centering. If <span class="Special">[width]</span> is not specified, it defaults to the value of<br>
<a class="Type" href="options.html#'textwidth'">'textwidth'</a>. (If <a class="Type" href="options.html#'textwidth'">'textwidth'</a> is 0, the default is 80.)<br>
For example:<br>
<br>
<div class="helpExample"> :1,5center 40</div>
<br>
results in the following:<br>
<br>
<span class="PreProc">I taught for a while. One</span><br>
<span class="PreProc">time, I was stopped by the</span><br>
<span class="PreProc">Fort Worth police, because my</span><br>
<span class="PreProc">homework was too hard. True</span><br>
<span class="PreProc">story.</span><br>
<br>
<br>
RIGHT ALIGNMENT<br>
<br>
Similarly, the ":right" command right-justifies the text:<br>
<br>
<div class="helpExample"> :1,5right 37</div>
<br>
gives this result:<br>
<br>
<span class="PreProc">I taught for a while. One</span><br>
<span class="PreProc">time, I was stopped by the</span><br>
<span class="PreProc">Fort Worth police, because my</span><br>
<span class="PreProc">homework was too hard. True</span><br>
<span class="PreProc">story.</span><br>
<br>
LEFT ALIGNMENT<br>
<br>
Finally there is this command:<br>
<br>
<div class="helpExample"> :{range}left [margin]</div>
<br>
Unlike ":center" and ":right", however, the argument to ":left" is not the<br>
length of the line. Instead it is the left margin. If it is omitted, the<br>
text will be put against the left side of the screen (using a zero margin<br>
would do the same). If it is 5, the text will be indented 5 spaces. For<br>
example, use these commands:<br>
<br>
<div class="helpExample"> :1left 5<br>
:2,5left</div>
<br>
This results in the following:<br>
<br>
<span class="PreProc">I taught for a while. One</span><br>
<span class="PreProc">time, I was stopped by the</span><br>
<span class="PreProc">Fort Worth police, because my</span><br>
<span class="PreProc">homework was too hard. True</span><br>
<span class="PreProc">story.</span><br>
<br>
<br>
JUSTIFYING TEXT<br>
<br>
Vim has no built-in way of justifying text. However, there is a neat macro<br>
package that does the job. To use this package, execute the following<br>
command:<br>
<br>
<div class="helpExample"> :packadd justify</div>
<br>
Or put this line in your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<br>
<div class="helpExample"> packadd! justify</div>
<br>
This Vim script file defines a new visual command "_j". To justify a block of<br>
text, highlight the text in Visual mode and then execute "_j".<br>
Look in the file for more explanations. To go there, do "gf" on this name:<br>
$VIMRUNTIME/pack/dist/opt/justify/plugin/justify.vim.<br>
<br>
An alternative is to filter the text through an external program. Example:<br>
<br>
<div class="helpExample"> :%!fmt</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_25.html#25.3" name="25.3">25.3</a> Indents and tabs<br>
<br>
Indents can be used to make text stand out from the rest. The example texts<br>
in this manual, for example, are indented by eight spaces or a tab. You would<br>
normally enter this by typing a tab at the start of each line. Take this<br>
text:<br>
<span class="PreProc">the first line</span><br>
<span class="PreProc">the second line</span><br>
<br>
This is entered by typing a tab, some text, <span class="Special"><Enter></span>, tab and more text.<br>
The <a class="Type" href="options.html#'autoindent'">'autoindent'</a> option inserts indents automatically:<br>
<br>
<div class="helpExample"> :set autoindent</div>
<br>
When a new line is started it gets the same indent as the previous line. In<br>
the above example, the tab after the <span class="Special"><Enter></span> is not needed anymore.<br>
<br>
<br>
INCREASING INDENT<br>
<br>
To increase the amount of indent in a line, use the ">" operator. Often this<br>
is used as ">>", which adds indent to the current line.<br>
The amount of indent added is specified with the <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> option. The<br>
default value is 8. To make ">>" insert four spaces worth of indent, for<br>
example, type this:<br>
<br>
<div class="helpExample"> :set shiftwidth=4</div>
<br>
When used on the second line of the example text, this is what you get:<br>
<br>
<span class="PreProc">the first line</span><br>
<span class="PreProc">the second line</span><br>
<br>
"4>>" will increase the indent of four lines.<br>
<br>
<br>
TABSTOP<br>
<br>
If you want to make indents a multiple of 4, you set <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> to 4. But<br>
when pressing a <span class="Special"><Tab></span> you still get 8 spaces worth of indent. To change this,<br>
set the <a class="Type" href="options.html#'softtabstop'">'softtabstop'</a> option:<br>
<br>
<div class="helpExample"> :set softtabstop=4</div>
<br>
This will make the <span class="Special"><Tab></span> key insert 4 spaces worth of indent. If there are<br>
already four spaces, a <span class="Special"><Tab></span> character is used (saving seven characters in the<br>
file). (If you always want spaces and no tab characters, set the <a class="Type" href="options.html#'expandtab'">'expandtab'</a><br>
option.)<br>
<br>
<span class="Todo">Note</span>:<br>
You could set the <a class="Type" href="options.html#'tabstop'">'tabstop'</a> option to 4. However, if you edit the<br>
file another time, with <a class="Type" href="options.html#'tabstop'">'tabstop'</a> set to the default value of 8, it<br>
will look wrong. In other programs and when printing the indent will<br>
also be wrong. Therefore it is recommended to keep <a class="Type" href="options.html#'tabstop'">'tabstop'</a> at eight<br>
all the time. That's the standard value everywhere.<br>
<br>
<br>
CHANGING TABS<br>
<br>
You edit a file which was written with a tabstop of 3. In Vim it looks ugly,<br>
because it uses the normal tabstop value of 8. You can fix this by setting<br>
<a class="Type" href="options.html#'tabstop'">'tabstop'</a> to 3. But you have to do this every time you edit this file.<br>
Vim can change the use of tabstops in your file. First, set <a class="Type" href="options.html#'tabstop'">'tabstop'</a> to<br>
make the indents look good, then use the ":retab" command:<br>
<br>
<div class="helpExample"> :set tabstop=3<br>
:retab 8</div>
<br>
The ":retab" command will change <a class="Type" href="options.html#'tabstop'">'tabstop'</a> to 8, while changing the text such<br>
that it looks the same. It changes spans of white space into tabs and spaces<br>
for this. You can now write the file. Next time you edit it the indents will<br>
be right without setting an option.<br>
Warning: When using ":retab" on a program, it may change white space inside<br>
a string constant. Therefore it's a good habit to use "\t" instead of a<br>
real tab.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_25.html#25.4" name="25.4">25.4</a> Dealing with long lines<br>
<br>
Sometimes you will be editing a file that is wider than the number of columns<br>
in the window. When that occurs, Vim wraps the lines so that everything fits<br>
on the screen.<br>
If you switch the <a class="Type" href="options.html#'wrap'">'wrap'</a> option off, each line in the file shows up as one<br>
line on the screen. Then the ends of the long lines disappear off the screen<br>
to the right.<br>
When you move the cursor to a character that can't be seen, Vim will scroll<br>
the text to show it. This is like moving a viewport over the text in the<br>
horizontal direction.<br>
By default, Vim does not display a horizontal scrollbar in the GUI. If you<br>
want to enable one, use the following command:<br>
<br>
<div class="helpExample"> :set guioptions+=b</div>
<br>
One horizontal scrollbar will appear at the bottom of the Vim window.<br>
<br>
If you don't have a scrollbar or don't want to use it, use these commands to<br>
scroll the text. The cursor will stay in the same place, but it's moved back<br>
into the visible text if necessary.<br>
<br>
zh scroll right<br>
4zh scroll four characters right<br>
zH scroll half a window width right<br>
ze scroll right to put the cursor at the end<br>
zl scroll left<br>
4zl scroll four characters left<br>
zL scroll half a window width left<br>
zs scroll left to put the cursor at the start<br>
<br>
Let's attempt to show this with one line of text. The cursor is on the "w" of<br>
"which". The "current window" above the line indicates the text that is<br>
currently visible. The "window"s below the text indicate the text that is<br>
visible after the command left of it.<br>
<br>
|<-- current window -->|<br>
<span class="PreProc">some long text, part of which is visible in the window</span><br>
ze |<-- window -->|<br>
zH |<-- window -->|<br>
4zh |<-- window -->|<br>
zh |<-- window -->|<br>
zl |<-- window -->|<br>
4zl |<-- window -->|<br>
zL |<-- window -->|<br>
zs |<-- window -->|<br>
<br>
<br>
MOVING WITH WRAP OFF<br>
<br>
When <a class="Type" href="options.html#'wrap'">'wrap'</a> is off and the text has scrolled horizontally, you can use the<br>
following commands to move the cursor to a character you can see. Thus text<br>
left and right of the window is ignored. These never cause the text to<br>
scroll:<br>
<br>
g0 to first visible character in this line<br>
g^ to first non-blank visible character in this line<br>
gm to middle of this line<br>
g$ to last visible character in this line<br>
<br>
|<-- window -->|<br>
<span class="PreProc">some long text, part of which is visible</span><br>
g0 g^ gm g$<br>
<br>
<br>
<span class="Statement">BREAKING AT WORDS </span><a class="Constant" href="usr_25.html#edit-no-break" name="edit-no-break">edit-no-break</a><br>
<br>
When preparing text for use by another program, you might have to make<br>
paragraphs without a line break. A disadvantage of using <a class="Type" href="options.html#'nowrap'">'nowrap'</a> is that you<br>
can't see the whole sentence you are working on. When <a class="Type" href="options.html#'wrap'">'wrap'</a> is on, words are<br>
broken halfway, which makes them hard to read.<br>
A good solution for editing this kind of paragraph is setting the<br>
<a class="Type" href="options.html#'linebreak'">'linebreak'</a> option. Vim then breaks lines at an appropriate place when<br>
displaying the line. The text in the file remains unchanged.<br>
Without <a class="Type" href="options.html#'linebreak'">'linebreak'</a> text might look like this:<br>
<br>
+---------------------------------+<br>
|letter generation program for a b|<br>
|ank. They wanted to send out a s|<br>
|pecial, personalized letter to th|<br>
|eir richest 1000 customers. Unfo|<br>
|rtunately for the programmer, he |<br>
+---------------------------------+<br>
After:<br>
<br>
<div class="helpExample"> :set linebreak</div>
<br>
it looks like this:<br>
<br>
+---------------------------------+<br>
|letter generation program for a |<br>
|bank. They wanted to send out a |<br>
|special, personalized letter to |<br>
|their richest 1000 customers. |<br>
|Unfortunately for the programmer,|<br>
+---------------------------------+<br>
<br>
Related options:<br>
<a class="Type" href="options.html#'breakat'">'breakat'</a> specifies the characters where a break can be inserted.<br>
<a class="Type" href="options.html#'showbreak'">'showbreak'</a> specifies a string to show at the start of broken line.<br>
Set <a class="Type" href="options.html#'textwidth'">'textwidth'</a> to zero to avoid a paragraph to be split.<br>
<br>
<br>
MOVING BY VISIBLE LINES<br>
<br>
The "j" and "k" commands move to the next and previous lines. When used on<br>
a long line, this means moving a lot of screen lines at once.<br>
To move only one screen line, use the "gj" and "gk" commands. When a line<br>
doesn't wrap they do the same as "j" and "k". When the line does wrap, they<br>
move to a character displayed one line below or above.<br>
You might like to use these mappings, which bind these movement commands to<br>
the cursor keys:<br>
<br>
<div class="helpExample"> :map <Up> gk<br>
:map <Down> gj</div>
<br>
<br>
<span class="Statement">TURNING A PARAGRAPH INTO ONE LINE </span><a class="Constant" href="usr_25.html#edit-paragraph-join" name="edit-paragraph-join">edit-paragraph-join</a><br>
<br>
If you want to import text into a program like MS-Word, each paragraph should<br>
be a single line. If your paragraphs are currently separated with empty<br>
lines, this is how you turn each paragraph into a single line:<br>
<br>
<div class="helpExample"> :g/./,/^$/join</div>
<br>
That looks complicated. Let's break it up in pieces:<br>
<br>
:g/./ A ":global" command that finds all lines that contain<br>
at least one character.<br>
,/^$/ A range, starting from the current line (the non-empty<br>
line) until an empty line.<br>
join The ":join" command joins the range of lines together<br>
into one line.<br>
<br>
Starting with this text, containing eight lines broken at column 30:<br>
<br>
+----------------------------------+<br>
|A letter generation program |<br>
|for a bank. They wanted to |<br>
|send out a special, |<br>
|personalized letter. |<br>
| |<br>
|To their richest 1000 |<br>
|customers. Unfortunately for |<br>
|the programmer, |<br>
+----------------------------------+<br>
<br>
You end up with two lines:<br>
<br>
+----------------------------------+<br>
|A letter generation program for a |<br>
|bank. They wanted to send out a s|<br>
|pecial, personalized letter. |<br>
|To their richest 1000 customers. |<br>
|Unfortunately for the programmer, |<br>
+----------------------------------+<br>
<br>
<span class="Todo">Note</span> that this doesn't work when the separating line is blank but not empty;<br>
when it contains spaces and/or tabs. This command does work with blank lines:<br>
<br>
<div class="helpExample"> :g/\S/,/^\s*$/join</div>
<br>
This still requires a blank or empty line at the end of the file for the last<br>
paragraph to be joined.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_25.html#25.5" name="25.5">25.5</a> Editing tables<br>
<br>
Suppose you are editing a table with four columns:<br>
<br>
<span class="PreProc">nice table test 1 test 2 test 3</span><br>
<span class="PreProc">input A 0.534</span><br>
<span class="PreProc">input B 0.913</span><br>
<br>
You need to enter numbers in the third column. You could move to the second<br>
line, use "A", enter a lot of spaces and type the text.<br>
For this kind of editing there is a special option:<br>
<br>
<div class="helpExample"> set virtualedit=all</div>
<br>
Now you can move the cursor to positions where there isn't any text. This is<br>
called "virtual space". Editing a table is a lot easier this way.<br>
Move the cursor by searching for the header of the last column:<br>
<br>
<div class="helpExample"> /test 3</div>
<br>
Now press "j" and you are right where you can enter the value for "input A".<br>
Typing "0.693" results in:<br>
<br>
<span class="PreProc">nice table test 1 test 2 test 3</span><br>
<span class="PreProc">input A 0.534 0.693</span><br>
<span class="PreProc">input B 0.913</span><br>
<br>
Vim has automatically filled the gap in front of the new text for you. Now,<br>
to enter the next field in this column use "Bj". "B" moves back to the start<br>
of a white space separated word. Then "j" moves to the place where the next<br>
field can be entered.<br>
<br>
<span class="Todo">Note</span>:<br>
You can move the cursor anywhere in the display, also beyond the end<br>
of a line. But Vim will not insert spaces there, until you insert a<br>
character in that position.<br>
<br>
<br>
COPYING A COLUMN<br>
<br>
You want to add a column, which should be a copy of the third column and<br>
placed before the "test 1" column. Do this in seven steps:<br>
1. Move the cursor to the left upper corner of this column, e.g., with<br>
"/test 3".<br>
2. Press <span class="Special">CTRL-V</span> to start blockwise Visual mode.<br>
3. Move the cursor down two lines with "2j". You are now in "virtual space":<br>
the "input B" line of the "test 3" column.<br>
4. Move the cursor right, to include the whole column in the selection, plus<br>
the space that you want between the columns. "9l" should do it.<br>
5. Yank the selected rectangle with "y".<br>
6. Move the cursor to "test 1", where the new column must be placed.<br>
7. Press "P".<br>
<br>
The result should be:<br>
<br>
<span class="PreProc">nice table test 3 test 1 test 2 test 3</span><br>
<span class="PreProc">input A 0.693 0.534 0.693</span><br>
<span class="PreProc">input B 0.913</span><br>
<br>
Notice that the whole "test 1" column was shifted right, also the line where<br>
the "test 3" column didn't have text.<br>
<br>
Go back to non-virtual cursor movements with:<br>
<br>
<div class="helpExample"> :set virtualedit=</div>
<br>
<br>
VIRTUAL REPLACE MODE<br>
<br>
The disadvantage of using <a class="Type" href="options.html#'virtualedit'">'virtualedit'</a> is that it "feels" different. You<br>
can't recognize tabs or spaces beyond the end of line when moving the cursor<br>
around. Another method can be used: Virtual Replace mode.<br>
Suppose you have a line in a table that contains both tabs and other<br>
characters. Use "rx" on the first tab:<br>
<br>
<span class="PreProc">inp 0.693 0.534 0.693</span><br>
<br>
|<br>
rx |<br>
V<br>
<br>
<span class="PreProc">inpx0.693 0.534 0.693</span><br>
<br>
The layout is messed up. To avoid that, use the "gr" command:<br>
<br>
<span class="PreProc">inp 0.693 0.534 0.693</span><br>
<br>
|<br>
grx |<br>
V<br>
<br>
<span class="PreProc">inpx 0.693 0.534 0.693</span><br>
<br>
What happens is that the "gr" command makes sure the new character takes the<br>
right amount of screen space. Extra spaces or tabs are inserted to fill the<br>
gap. Thus what actually happens is that a tab is replaced by "x" and then<br>
blanks added to make the text after it keep its place. In this case a<br>
tab is inserted.<br>
When you need to replace more than one character, you use the "R" command<br>
to go to Replace mode (see <a class="Identifier" href="usr_04.html#04.9">04.9</a>). This messes up the layout and replaces<br>
the wrong characters:<br>
<br>
<span class="PreProc">inp 0 0.534 0.693</span><br>
<br>
|<br>
R0.786 |<br>
V<br>
<br>
<span class="PreProc">inp 0.78634 0.693</span><br>
<br>
The "gR" command uses Virtual Replace mode. This preserves the layout:<br>
<br>
<span class="PreProc">inp 0 0.534 0.693</span><br>
<br>
|<br>
gR0.786 |<br>
V<br>
<br>
<span class="PreProc">inp 0.786 0.534 0.693</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_26.html">usr_26.txt</a> Repeating<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。