代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_06 - 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_06<br />
<a name="top"></a><h1>usr_06 - 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_06.html" name="usr_06.txt">usr_06.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2009 Oct 28<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Using syntax highlighting<br>
<br>
<br>
Black and white text is boring. With colors your file comes to life. This<br>
not only looks nice, it also speeds up your work. Change the colors used for<br>
the different sorts of text. Print your text, with the colors you see on the<br>
screen.<br>
<br>
<a class="Identifier" href="usr_06.html#06.1">06.1</a> Switching it on<br>
<a class="Identifier" href="usr_06.html#06.2">06.2</a> No or wrong colors?<br>
<a class="Identifier" href="usr_06.html#06.3">06.3</a> Different colors<br>
<a class="Identifier" href="usr_06.html#06.4">06.4</a> With colors or without colors<br>
<a class="Identifier" href="usr_06.html#06.5">06.5</a> Printing with colors<br>
<a class="Identifier" href="usr_06.html#06.6">06.6</a> Further reading<br>
<br>
Next chapter: <a class="Identifier" href="usr_07.html">usr_07.txt</a> Editing more than one file<br>
Previous chapter: <a class="Identifier" href="usr_05.html">usr_05.txt</a> Set your settings<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_06.html#06.1" name="06.1">06.1</a> Switching it on<br>
<br>
It all starts with one simple command:<br>
<br>
<div class="helpExample"> :syntax enable</div>
<br>
That should work in most situations to get color in your files. Vim will<br>
automagically detect the type of file and load the right syntax highlighting.<br>
Suddenly comments are blue, keywords brown and strings red. This makes it<br>
easy to overview the file. After a while you will find that black&white text<br>
slows you down!<br>
<br>
If you always want to use syntax highlighting, put the ":syntax enable"<br>
command in your <a class="Identifier" href="starting.html#vimrc">vimrc</a> file.<br>
<br>
If you want syntax highlighting only when the terminal supports colors, you<br>
can put this in your <a class="Identifier" href="starting.html#vimrc">vimrc</a> file:<br>
<br>
<div class="helpExample"> if &t_Co > 1<br>
syntax enable<br>
endif</div>
<br>
If you want syntax highlighting only in the GUI version, put the ":syntax<br>
enable" command in your <a class="Identifier" href="gui.html#gvimrc">gvimrc</a> file.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_06.html#06.2" name="06.2">06.2</a> No or wrong colors?<br>
<br>
There can be a number of reasons why you don't see colors:<br>
<br>
- Your terminal does not support colors.<br>
Vim will use bold, italic and underlined text, but this doesn't look<br>
very nice. You probably will want to try to get a terminal with<br>
colors. For Unix, I recommend the xterm from the XFree86 project:<br>
<a class="Identifier" href="syntax.html#xfree-xterm">xfree-xterm</a>.<br>
<br>
- Your terminal does support colors, but Vim doesn't know this.<br>
Make sure your $TERM setting is correct. For example, when using an<br>
xterm that supports colors:<br>
<br>
<div class="helpExample"> setenv TERM xterm-color</div>
<br>
or (depending on your shell):<br>
<br>
<div class="helpExample"> TERM=xterm-color; export TERM</div>
<br>
The terminal name must match the terminal you are using. If it<br>
still doesn't work, have a look at <a class="Identifier" href="syntax.html#xterm-color">xterm-color</a>, which shows a few<br>
ways to make Vim display colors (not only for an xterm).<br>
<br>
- The file type is not recognized.<br>
Vim doesn't know all file types, and sometimes it's near to impossible<br>
to tell what language a file uses. Try this command:<br>
<br>
<div class="helpExample"> :set filetype</div>
<br>
If the result is "filetype=" then the problem is indeed that Vim<br>
doesn't know what type of file this is. You can set the type<br>
manually:<br>
<br>
<div class="helpExample"> :set filetype=fortran</div>
<br>
To see which types are available, look in the directory<br>
$VIMRUNTIME/syntax. For the GUI you can use the Syntax menu.<br>
Setting the filetype can also be done with a <a class="Identifier" href="options.html#modeline">modeline</a>, so that the<br>
file will be highlighted each time you edit it. For example, this<br>
line can be used in a Makefile (put it near the start or end of the<br>
file):<br>
<br>
<div class="helpExample"> # vim: syntax=make</div>
<br>
You might know how to detect the file type yourself. Often the file<br>
name extension (after the dot) can be used.<br>
See <a class="Identifier" href="filetype.html#new-filetype">new-filetype</a> for how to tell Vim to detect that file type.<br>
<br>
- There is no highlighting for your file type.<br>
You could try using a similar file type by manually setting it as<br>
mentioned above. If that isn't good enough, you can write your own<br>
syntax file, see <a class="Identifier" href="syntax.html#mysyntaxfile">mysyntaxfile</a>.<br>
<br>
<br>
Or the colors could be wrong:<br>
<br>
- The colored text is very hard to read.<br>
Vim guesses the background color that you are using. If it is black<br>
(or another dark color) it will use light colors for text. If it is<br>
white (or another light color) it will use dark colors for text. If<br>
Vim guessed wrong the text will be hard to read. To solve this, set<br>
the <a class="Type" href="options.html#'background'">'background'</a> option. For a dark background:<br>
<br>
<div class="helpExample"> :set background=dark</div>
<br>
And for a light background:<br>
<br>
<div class="helpExample"> :set background=light</div>
<br>
Make sure you put this _before_ the ":syntax enable" command,<br>
otherwise the colors will already have been set. You could do<br>
":syntax reset" after setting <a class="Type" href="options.html#'background'">'background'</a> to make Vim set the default<br>
colors again.<br>
<br>
- The colors are wrong when scrolling bottom to top.<br>
Vim doesn't read the whole file to parse the text. It starts parsing<br>
wherever you are viewing the file. That saves a lot of time, but<br>
sometimes the colors are wrong. A simple fix is hitting <span class="Special">CTRL-L</span>. Or<br>
scroll back a bit and then forward again.<br>
For a real fix, see <a class="Identifier" href="syntax.html#:syn-sync">:syn-sync</a>. Some syntax files have a way to make<br>
it look further back, see the help for the specific syntax file. For<br>
example, <a class="Identifier" href="syntax.html#tex.vim">tex.vim</a> for the TeX syntax.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_06.html#06.3" name="06.3">06.3</a> Different colors <a class="Constant" href="usr_06.html#:syn-default-override" name=":syn-default-override">:syn-default-override</a><br>
<br>
If you don't like the default colors, you can select another color scheme. In<br>
the GUI use the Edit/Color Scheme menu. You can also type the command:<br>
<br>
<div class="helpExample"> :colorscheme evening</div>
<br>
"evening" is the name of the color scheme. There are several others you might<br>
want to try out. Look in the directory $VIMRUNTIME/colors.<br>
<br>
When you found the color scheme that you like, add the ":colorscheme" command<br>
to your <a class="Identifier" href="starting.html#vimrc">vimrc</a> file.<br>
<br>
You could also write your own color scheme. This is how you do it:<br>
<br>
1. Select a color scheme that comes close. Copy this file to your own Vim<br>
directory. For Unix, this should work:<br>
<br>
<div class="helpExample"> !mkdir ~/.vim/colors<br>
!cp $VIMRUNTIME/colors/morning.vim ~/.vim/colors/mine.vim</div>
<br>
This is done from Vim, because it knows the value of $VIMRUNTIME.<br>
<br>
2. Edit the color scheme file. These entries are useful:<br>
<br>
term attributes in a B&W terminal<br>
cterm attributes in a color terminal<br>
ctermfg foreground color in a color terminal<br>
ctermbg background color in a color terminal<br>
gui attributes in the GUI<br>
guifg foreground color in the GUI<br>
guibg background color in the GUI<br>
<br>
For example, to make comments green:<br>
<br>
<div class="helpExample"> :highlight Comment ctermfg=green guifg=green</div>
<br>
Attributes you can use for "cterm" and "gui" are "bold" and "underline".<br>
If you want both, use "bold,underline". For details see the <a class="Identifier" href="syntax.html#:highlight">:highlight</a><br>
command.<br>
<br>
3. Tell Vim to always use your color scheme. Put this line in your <a class="Identifier" href="starting.html#vimrc">vimrc</a>:<br>
<br>
<div class="helpExample"> colorscheme mine</div>
<br>
If you want to see what the most often used color combinations look like, use<br>
this command:<br>
<br>
<div class="helpExample"> :runtime syntax/colortest.vim</div>
<br>
You will see text in various color combinations. You can check which ones are<br>
readable and look nice.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_06.html#06.4" name="06.4">06.4</a> With colors or without colors<br>
<br>
Displaying text in color takes a lot of effort. If you find the displaying<br>
too slow, you might want to disable syntax highlighting for a moment:<br>
<br>
<div class="helpExample"> :syntax clear</div>
<br>
When editing another file (or the same one) the colors will come back.<br>
<br>
<a class="Constant" href="usr_06.html#:syn-off" name=":syn-off">:syn-off</a><br>
If you want to stop highlighting completely use:<br>
<br>
<div class="helpExample"> :syntax off</div>
<br>
This will completely disable syntax highlighting and remove it immediately for<br>
all buffers.<br>
<br>
<a class="Constant" href="usr_06.html#:syn-manual" name=":syn-manual">:syn-manual</a><br>
If you want syntax highlighting only for specific files, use this:<br>
<br>
<div class="helpExample"> :syntax manual</div>
<br>
This will enable the syntax highlighting, but not switch it on automatically<br>
when starting to edit a buffer. To switch highlighting on for the current<br>
buffer, set the <a class="Type" href="options.html#'syntax'">'syntax'</a> option:<br>
<br>
<div class="helpExample"> :set syntax=ON</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_06.html#06.5" name="06.5">06.5</a> Printing with colors <a class="Constant" href="usr_06.html#syntax-printing" name="syntax-printing">syntax-printing</a><br>
<br>
In the MS-Windows version you can print the current file with this command:<br>
<br>
<div class="helpExample"> :hardcopy</div>
<br>
You will get the usual printer dialog, where you can select the printer and a<br>
few settings. If you have a color printer, the paper output should look the<br>
same as what you see inside Vim. But when you use a dark background the<br>
colors will be adjusted to look good on white paper.<br>
<br>
There are several options that change the way Vim prints:<br>
<a class="Type" href="options.html#'printdevice'">'printdevice'</a><br>
<a class="Type" href="options.html#'printheader'">'printheader'</a><br>
<a class="Type" href="options.html#'printfont'">'printfont'</a><br>
<a class="Type" href="options.html#'printoptions'">'printoptions'</a><br>
<br>
To print only a range of lines, use Visual mode to select the lines and then<br>
type the command:<br>
<br>
<div class="helpExample"> v100j:hardcopy</div>
<br>
"v" starts Visual mode. "100j" moves a hundred lines down, they will be<br>
highlighted. Then ":hardcopy" will print those lines. You can use other<br>
commands to move in Visual mode, of course.<br>
<br>
This also works on Unix, if you have a PostScript printer. Otherwise, you<br>
will have to do a bit more work. You need to convert the text to HTML first,<br>
and then print it from a web browser.<br>
<br>
Convert the current file to HTML with this command:<br>
<br>
<div class="helpExample"> :TOhtml</div>
<br>
In case that doesn't work:<br>
<br>
<div class="helpExample"> :source $VIMRUNTIME/syntax/2html.vim</div>
<br>
You will see it crunching away, this can take quite a while for a large file.<br>
Some time later another window shows the HTML code. Now write this somewhere<br>
(doesn't matter where, you throw it away later):<br>
<br>
<div class="helpExample"> :write main.c.html</div>
<br>
Open this file in your favorite browser and print it from there. If all goes<br>
well, the output should look exactly as it does in Vim. See <a class="Identifier" href="syntax.html#2html.vim">2html.vim</a> for<br>
details. Don't forget to delete the HTML file when you are done with it.<br>
<br>
Instead of printing, you could also put the HTML file on a web server, and let<br>
others look at the colored text.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_06.html#06.6" name="06.6">06.6</a> Further reading<br>
<br>
<a class="Identifier" href="usr_44.html">usr_44.txt</a> Your own syntax highlighted.<br>
<a class="Identifier" href="syntax.html#syntax">syntax</a> All the details.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_07.html">usr_07.txt</a> Editing more than one file<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。