代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_21 - 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_21<br />
<a name="top"></a><h1>usr_21 - 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_21.html" name="usr_21.txt">usr_21.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2012 Nov 02<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Go away and come back<br>
<br>
<br>
This chapter goes into mixing the use of other programs with Vim. Either by<br>
executing program from inside Vim or by leaving Vim and coming back later.<br>
Furthermore, this is about the ways to remember the state of Vim and restore<br>
it later.<br>
<br>
<a class="Identifier" href="usr_21.html#21.1">21.1</a> Suspend and resume<br>
<a class="Identifier" href="usr_21.html#21.2">21.2</a> Executing shell commands<br>
<a class="Identifier" href="usr_21.html#21.3">21.3</a> Remembering information; viminfo<br>
<a class="Identifier" href="usr_21.html#21.4">21.4</a> Sessions<br>
<a class="Identifier" href="usr_21.html#21.5">21.5</a> Views<br>
<a class="Identifier" href="usr_21.html#21.6">21.6</a> Modelines<br>
<br>
Next chapter: <a class="Identifier" href="usr_22.html">usr_22.txt</a> Finding the file to edit<br>
Previous chapter: <a class="Identifier" href="usr_20.html">usr_20.txt</a> Typing command-line commands 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_21.html#21.1" name="21.1">21.1</a> Suspend and resume<br>
<br>
Like most Unix programs Vim can be suspended by pressing <span class="Special">CTRL-Z</span>. This stops<br>
Vim and takes you back to the shell it was started in. You can then do any<br>
other commands until you are bored with them. Then bring back Vim with the<br>
"fg" command.<br>
<br>
<div class="helpExample"> CTRL-Z<br>
{any sequence of shell commands}<br>
fg</div>
<br>
You are right back where you left Vim, nothing has changed.<br>
In case pressing <span class="Special">CTRL-Z</span> doesn't work, you can also use ":suspend".<br>
Don't forget to bring Vim back to the foreground, you would lose any changes<br>
that you made!<br>
<br>
Only Unix has support for this. On other systems Vim will start a shell for<br>
you. This also has the functionality of being able to execute shell commands.<br>
But it's a new shell, not the one that you started Vim from.<br>
When you are running the GUI you can't go back to the shell where Vim was<br>
started. <span class="Special">CTRL-Z</span> will minimize the Vim window instead.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_21.html#21.2" name="21.2">21.2</a> Executing shell commands<br>
<br>
To execute a single shell command from Vim use ":!<span class="Special">{command}</span>". For example, to<br>
see a directory listing:<br>
<br>
<div class="helpExample"> :!ls<br>
:!dir</div>
<br>
The first one is for Unix, the second one for MS-Windows.<br>
Vim will execute the program. When it ends you will get a prompt to hit<br>
<span class="Special"><Enter></span>. This allows you to have a look at the output from the command before<br>
returning to the text you were editing.<br>
The "!" is also used in other places where a program is run. Let's take<br>
a look at an overview:<br>
<br>
:!<span class="Special">{program}</span> execute <span class="Special">{program}</span><br>
:r !<span class="Special">{program}</span> execute <span class="Special">{program}</span> and read its output<br>
:w !<span class="Special">{program}</span> execute <span class="Special">{program}</span> and send text to its input<br>
:<span class="Special">[range]</span>!<span class="Special">{program}</span> filter text through <span class="Special">{program}</span><br>
<br>
Notice that the presence of a range before "!<span class="Special">{program}</span>" makes a big<br>
difference. Without it executes the program normally, with the range a number<br>
of text lines is filtered through the program.<br>
<br>
Executing a whole row of programs this way is possible. But a shell is much<br>
better at it. You can start a new shell this way:<br>
<br>
<div class="helpExample"> :shell</div>
<br>
This is similar to using <span class="Special">CTRL-Z</span> to suspend Vim. The difference is that a new<br>
shell is started.<br>
<br>
When using the GUI the shell will be using the Vim window for its input and<br>
output. Since Vim is not a terminal emulator, this will not work perfectly.<br>
If you have trouble, try toggling the <a class="Type" href="options.html#'guipty'">'guipty'</a> option. If this still doesn't<br>
work well enough, start a new terminal to run the shell in. For example with:<br>
<br>
<div class="helpExample"> :!xterm&</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_21.html#21.3" name="21.3">21.3</a> Remembering information; viminfo<br>
<br>
After editing for a while you will have text in registers, marks in various<br>
files, a command line history filled with carefully crafted commands. When<br>
you exit Vim all of this is lost. But you can get it back!<br>
<br>
The viminfo file is designed to store status information:<br>
<br>
Command-line and Search pattern history<br>
Text in registers<br>
Marks for various files<br>
The buffer list<br>
Global variables<br>
<br>
Each time you exit Vim it will store this information in a file, the viminfo<br>
file. When Vim starts again, the viminfo file is read and the information<br>
restored.<br>
<br>
The <a class="Type" href="options.html#'viminfo'">'viminfo'</a> option is set by default to restore a limited number of items.<br>
You might want to set it to remember more information. This is done through<br>
the following command:<br>
<br>
<div class="helpExample"> :set viminfo=string</div>
<br>
The string specifies what to save. The syntax of this string is an option<br>
character followed by an argument. The option/argument pairs are separated by<br>
commas.<br>
Take a look at how you can build up your own viminfo string. First, the '<br>
option is used to specify how many files for which you save marks (a-z). Pick<br>
a nice even number for this option (1000, for instance). Your command now<br>
looks like this:<br>
<br>
<div class="helpExample"> :set viminfo='1000</div>
<br>
The f option controls whether global marks (A-Z and 0-9) are stored. If this<br>
option is 0, none are stored. If it is 1 or you do not specify an f option,<br>
the marks are stored. You want this feature, so now you have this:<br>
<br>
<div class="helpExample"> :set viminfo='1000,f1</div>
<br>
The < option controls how many lines are saved for each of the registers. By<br>
default, all the lines are saved. If 0, nothing is saved. To avoid adding<br>
thousands of lines to your viminfo file (which might never get used and makes<br>
starting Vim slower) you use a maximum of 500 lines:<br>
<br>
<div class="helpExample"> :set viminfo='1000,f1,<500</div>
<br>
Other options you might want to use:<br>
: number of lines to save from the command line history<br>
@ number of lines to save from the input line history<br>
/ number of lines to save from the search history<br>
r removable media, for which no marks will be stored (can be<br>
used several times)<br>
! global variables that start with an uppercase letter and<br>
don't contain lowercase letters<br>
h disable <a class="Type" href="options.html#'hlsearch'">'hlsearch'</a> highlighting when starting<br>
% the buffer list (only restored when starting Vim without file<br>
arguments)<br>
c convert the text using <a class="Type" href="options.html#'encoding'">'encoding'</a><br>
n name used for the viminfo file (must be the last option)<br>
<br>
See the <a class="Type" href="options.html#'viminfo'">'viminfo'</a> option and <a class="Identifier" href="starting.html#viminfo-file">viminfo-file</a> for more information.<br>
<br>
When you run Vim multiple times, the last one exiting will store its<br>
information. This may cause information that previously exiting Vims stored<br>
to be lost. Each item can be remembered only once.<br>
<br>
<br>
GETTING BACK TO WHERE YOU STOPPED VIM<br>
<br>
You are halfway editing a file and it's time to leave for holidays. You exit<br>
Vim and go enjoy yourselves, forgetting all about your work. After a couple<br>
of weeks you start Vim, and type:<br>
<br>
<div class="helpExample"> '0</div>
<br>
And you are right back where you left Vim. So you can get on with your work.<br>
Vim creates a mark each time you exit Vim. The last one is '0. The<br>
position that '0 pointed to is made '1. And '1 is made to '2, and so forth.<br>
Mark '9 is lost.<br>
The <a class="Identifier" href="motion.html#:marks">:marks</a> command is useful to find out where '0 to '9 will take you.<br>
<br>
<br>
GETTING BACK TO SOME FILE<br>
<br>
If you want to go back to a file that you edited recently, but not when<br>
exiting Vim, there is a slightly more complicated way. You can see a list of<br>
files by typing the command:<br>
<br>
<div class="helpExample"> :oldfiles</div>
<span class="PreProc">1: ~/.viminfo</span><br>
<span class="PreProc">2: ~/text/resume.txt</span><br>
<span class="PreProc">3: /tmp/draft</span><br>
<br>
Now you would like to edit the second file, which is in the list preceded by<br>
"2:". You type:<br>
<br>
<div class="helpExample"> :e #<2</div>
<br>
Instead of ":e" you can use any command that has a file name argument, the<br>
"#<2" item works in the same place as "%" (current file name) and "#"<br>
(alternate file name). So you can also split the window to edit the third<br>
file:<br>
<br>
<div class="helpExample"> :split #<3</div>
<br>
That #<123 thing is a bit complicated when you just want to edit a file.<br>
Fortunately there is a simpler way:<br>
<br>
<div class="helpExample"> :browse oldfiles</div>
<span class="PreProc">1: ~/.viminfo</span><br>
<span class="PreProc">2: ~/text/resume.txt</span><br>
<span class="PreProc">3: /tmp/draft</span><br>
-- More --<br>
<br>
You get the same list of files as with <a class="Identifier" href="starting.html#:oldfiles">:oldfiles</a>. If you want to edit<br>
"resume.txt" first press "q" to stop the listing. You will get a prompt:<br>
<br>
<span class="PreProc">Type number and <Enter> (empty cancels):</span><br>
<br>
Type "2" and press <span class="Special"><Enter></span> to edit the second file.<br>
<br>
More info at <a class="Identifier" href="starting.html#:oldfiles">:oldfiles</a>, <a class="Identifier" href="eval.html#v:oldfiles">v:oldfiles</a> and <a class="Identifier" href="cmdline.html#c_#<">c_#<</a>.<br>
<br>
<br>
MOVE INFO FROM ONE VIM TO ANOTHER<br>
<br>
You can use the ":wviminfo" and ":rviminfo" commands to save and restore the<br>
information while still running Vim. This is useful for exchanging register<br>
contents between two instances of Vim, for example. In the first Vim do:<br>
<br>
<div class="helpExample"> :wviminfo! ~/tmp/viminfo</div>
<br>
And in the second Vim do:<br>
<br>
<div class="helpExample"> :rviminfo! ~/tmp/viminfo</div>
<br>
Obviously, the "w" stands for "write" and the "r" for "read".<br>
The ! character is used by ":wviminfo" to forcefully overwrite an existing<br>
file. When it is omitted, and the file exists, the information is merged into<br>
the file.<br>
The ! character used for ":rviminfo" means that all the information is<br>
used, this may overwrite existing information. Without the ! only information<br>
that wasn't set is used.<br>
These commands can also be used to store info and use it again later. You<br>
could make a directory full of viminfo files, each containing info for a<br>
different purpose.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_21.html#21.4" name="21.4">21.4</a> Sessions<br>
<br>
Suppose you are editing along, and it is the end of the day. You want to quit<br>
work and pick up where you left off the next day. You can do this by saving<br>
your editing session and restoring it the next day.<br>
A Vim session contains all the information about what you are editing.<br>
This includes things such as the file list, window layout, global variables,<br>
options and other information. (Exactly what is remembered is controlled by<br>
the <a class="Type" href="options.html#'sessionoptions'">'sessionoptions'</a> option, described below.)<br>
The following command creates a session file:<br>
<br>
<div class="helpExample"> :mksession vimbook.vim</div>
<br>
Later if you want to restore this session, you can use this command:<br>
<br>
<div class="helpExample"> :source vimbook.vim</div>
<br>
If you want to start Vim and restore a specific session, you can use the<br>
following command:<br>
<br>
<div class="helpExample"> vim -S vimbook.vim</div>
<br>
This tells Vim to read a specific file on startup. The 'S' stands for<br>
session (actually, you can source any Vim script with -S, thus it might as<br>
well stand for "source").<br>
<br>
The windows that were open are restored, with the same position and size as<br>
before. Mappings and option values are like before.<br>
What exactly is restored depends on the <a class="Type" href="options.html#'sessionoptions'">'sessionoptions'</a> option. The<br>
default value is "blank,buffers,curdir,folds,help,options,winsize".<br>
<br>
blank keep empty windows<br>
buffers all buffers, not only the ones in a window<br>
curdir the current directory<br>
folds folds, also manually created ones<br>
help the help window<br>
options all options and mappings<br>
winsize window sizes<br>
<br>
Change this to your liking. To also restore the size of the Vim window, for<br>
example, use:<br>
<br>
<div class="helpExample"> :set sessionoptions+=resize</div>
<br>
<br>
SESSION HERE, SESSION THERE<br>
<br>
The obvious way to use sessions is when working on different projects.<br>
Suppose you store your session files in the directory "~/.vim". You are<br>
currently working on the "secret" project and have to switch to the "boring"<br>
project:<br>
<br>
<div class="helpExample"> :wall<br>
:mksession! ~/.vim/secret.vim<br>
:source ~/.vim/boring.vim</div>
<br>
This first uses ":wall" to write all modified files. Then the current session<br>
is saved, using ":mksession!". This overwrites the previous session. The<br>
next time you load the secret session you can continue where you were at this<br>
point. And finally you load the new "boring" session.<br>
<br>
If you open help windows, split and close various windows, and generally mess<br>
up the window layout, you can go back to the last saved session:<br>
<br>
<div class="helpExample"> :source ~/.vim/boring.vim</div>
<br>
Thus you have complete control over whether you want to continue next time<br>
where you are now, by saving the current setup in a session, or keep the<br>
session file as a starting point.<br>
Another way of using sessions is to create a window layout that you like to<br>
use, and save this in a session. Then you can go back to this layout whenever<br>
you want.<br>
For example, this is a nice layout to use:<br>
<br>
+----------------------------------------+<br>
| VIM - main help file |<br>
| |<br>
|Move around: Use the cursor keys, or "h|<br>
|help.txt================================|<br>
|explorer | |<br>
|dir |~ |<br>
|dir |~ |<br>
|file |~ |<br>
|file |~ |<br>
|file |~ |<br>
|file |~ |<br>
|~/=========|[No File]===================|<br>
| |<br>
+----------------------------------------+<br>
<br>
This has a help window at the top, so that you can read this text. The narrow<br>
vertical window on the left contains a file explorer. This is a Vim plugin<br>
that lists the contents of a directory. You can select files to edit there.<br>
More about this in the next chapter.<br>
Create this from a just started Vim with:<br>
<br>
<div class="helpExample"> :help<br>
CTRL-W w<br>
:vertical split ~/</div>
<br>
You can resize the windows a bit to your liking. Then save the session with:<br>
<br>
<div class="helpExample"> :mksession ~/.vim/mine.vim</div>
<br>
Now you can start Vim with this layout:<br>
<br>
<div class="helpExample"> vim -S ~/.vim/mine.vim</div>
<br>
Hint: To open a file you see listed in the explorer window in the empty<br>
window, move the cursor to the filename and press "O". Double clicking with<br>
the mouse will also do this.<br>
<br>
<br>
UNIX AND MS-WINDOWS<br>
<br>
Some people have to do work on MS-Windows systems one day and on Unix another<br>
day. If you are one of them, consider adding "slash" and "unix" to<br>
<a class="Type" href="options.html#'sessionoptions'">'sessionoptions'</a>. The session files will then be written in a format that can<br>
be used on both systems. This is the command to put in your vimrc file:<br>
<br>
<div class="helpExample"> :set sessionoptions+=unix,slash</div>
<br>
Vim will use the Unix format then, because the MS-Windows Vim can read and<br>
write Unix files, but Unix Vim can't read MS-Windows format session files.<br>
Similarly, MS-Windows Vim understands file names with / to separate names, but<br>
Unix Vim doesn't understand \.<br>
<br>
<br>
SESSIONS AND VIMINFO<br>
<br>
Sessions store many things, but not the position of marks, contents of<br>
registers and the command line history. You need to use the viminfo feature<br>
for these things.<br>
In most situations you will want to use sessions separately from viminfo.<br>
This can be used to switch to another session, but keep the command line<br>
history. And yank text into registers in one session, and paste it back in<br>
another session.<br>
You might prefer to keep the info with the session. You will have to do<br>
this yourself then. Example:<br>
<br>
<div class="helpExample"> :mksession! ~/.vim/secret.vim<br>
:wviminfo! ~/.vim/secret.viminfo</div>
<br>
And to restore this again:<br>
<br>
<div class="helpExample"> :source ~/.vim/secret.vim<br>
:rviminfo! ~/.vim/secret.viminfo</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_21.html#21.5" name="21.5">21.5</a> Views<br>
<br>
A session stores the looks of the whole of Vim. When you want to store the<br>
properties for one window only, use a view.<br>
The use of a view is for when you want to edit a file in a specific way.<br>
For example, you have line numbers enabled with the <a class="Type" href="options.html#'number'">'number'</a> option and<br>
defined a few folds. Just like with sessions, you can remember this view on<br>
the file and restore it later. Actually, when you store a session, it stores<br>
the view of each window.<br>
There are two basic ways to use views. The first is to let Vim pick a name<br>
for the view file. You can restore the view when you later edit the same<br>
file. To store the view for the current window:<br>
<br>
<div class="helpExample"> :mkview</div>
<br>
Vim will decide where to store the view. When you later edit the same file<br>
you get the view back with this command:<br>
<br>
<div class="helpExample"> :loadview</div>
<br>
That's easy, isn't it?<br>
Now you want to view the file without the <a class="Type" href="options.html#'number'">'number'</a> option on, or with all<br>
folds open, you can set the options to make the window look that way. Then<br>
store this view with:<br>
<br>
<div class="helpExample"> :mkview 1</div>
<br>
Obviously, you can get this back with:<br>
<br>
<div class="helpExample"> :loadview 1</div>
<br>
Now you can switch between the two views on the file by using ":loadview" with<br>
and without the "1" argument.<br>
You can store up to ten views for the same file this way, one unnumbered<br>
and nine numbered 1 to 9.<br>
<br>
<br>
A VIEW WITH A NAME<br>
<br>
The second basic way to use views is by storing the view in a file with a name<br>
you choose. This view can be loaded while editing another file. Vim will<br>
then switch to editing the file specified in the view. Thus you can use this<br>
to quickly switch to editing another file, with all its options set as you<br>
saved them.<br>
For example, to save the view of the current file:<br>
<br>
<div class="helpExample"> :mkview ~/.vim/main.vim</div>
<br>
You can restore it with:<br>
<br>
<div class="helpExample"> :source ~/.vim/main.vim</div>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_21.html#21.6" name="21.6">21.6</a> Modelines<br>
<br>
When editing a specific file, you might set options specifically for that<br>
file. Typing these commands each time is boring. Using a session or view for<br>
editing a file doesn't work when sharing the file between several people.<br>
The solution for this situation is adding a modeline to the file. This is<br>
a line of text that tells Vim the values of options, to be used in this file<br>
only.<br>
A typical example is a C program where you make indents by a multiple of 4<br>
spaces. This requires setting the <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> option to 4. This modeline<br>
will do that:<br>
<br>
<span class="PreProc">/* vim:set shiftwidth=4: */</span><br>
<br>
Put this line as one of the first or last five lines in the file. When<br>
editing the file, you will notice that <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> will have been set to<br>
four. When editing another file, it's set back to the default value of eight.<br>
For some files the modeline fits well in the header, thus it can be put at<br>
the top of the file. For text files and other files where the modeline gets<br>
in the way of the normal contents, put it at the end of the file.<br>
<br>
The <a class="Type" href="options.html#'modelines'">'modelines'</a> option specifies how many lines at the start and end of the<br>
file are inspected for containing a modeline. To inspect ten lines:<br>
<br>
<div class="helpExample"> :set modelines=10</div>
<br>
The <a class="Type" href="options.html#'modeline'">'modeline'</a> option can be used to switch this off. Do this when you are<br>
working as root on Unix or Administrator on MS-Windows, or when you don't<br>
trust the files you are editing:<br>
<br>
<div class="helpExample"> :set nomodeline</div>
<br>
Use this format for the modeline:<br>
<br>
<span class="PreProc">any-text vim:set {option}={value} ... : any-text</span><br>
<br>
The "any-text" indicates that you can put any text before and after the part<br>
that Vim will use. This allows making it look like a comment, like what was<br>
done above with /* and */.<br>
The " vim:" part is what makes Vim recognize this line. There must be<br>
white space before "vim", or "vim" must be at the start of the line. Thus<br>
using something like "gvim:" will not work.<br>
The part between the colons is a ":set" command. It works the same way as<br>
typing the ":set" command, except that you need to insert a backslash before a<br>
colon (otherwise it would be seen as the end of the modeline).<br>
<br>
Another example:<br>
<br>
<span class="PreProc">// vim:set textwidth=72 dir=c\:\tmp: use c:\tmp here</span><br>
<br>
There is an extra backslash before the first colon, so that it's included in<br>
the ":set" command. The text after the second colon is ignored, thus a remark<br>
can be placed there.<br>
<br>
For more details see <a class="Identifier" href="options.html#modeline">modeline</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_22.html">usr_22.txt</a> Finding the file to edit<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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。