Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tag: v0.0.1
Fetching contributors…

Cannot retrieve contributors at this time

68 lines (53 sloc) 2.684 kB
<h3 id="splitting-screen">Splitting the Screen</h3>
<h4>Problem</h4>
<p>You want to view multiple files at one time. Or, you want to view different
positions in the same file at the same time.</p>
<p>For example, if you were editing source code in an unfamiliar programming
language, you may want to have the documentation and source visible at the
same time. Or, if you wanted to move text between multiple files, you could
view the source and target file together.</p>
<h4>Solution</h4>
<p>Use Vim's <i>split screen</i> feature to divide the screen into multiple panes,
each of which can display a file.</p>
<table>
<tr>
<th>Command</th>
<th>Action</th>
</tr>
<tr>
<td><tt>:split <var>file</var></tt></td>
<td>Splits the window horizontally.</td>
</tr>
<tr>
<td><tt>:vsplit <var>file</var></tt></td>
<td>Splits the window vertically.</td>
</tr>
</table>
<p>(If <var>file</var> is specified, that file is shown in the upper/left, as
appropriate, pane; if not, both panes show the current file).</p>
<p>To move between windows you use
<kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>w</kbd></kbd> (mnemonic: <i>control</i>
<i>w</i>indow). To move in a specific direction, add the relevant <a
href="#basic-navigation">movement key</a>. So, to move upwards:
<kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>w</kbd>+<kbd>k</kbd></kbd>.</p>
<p>To close the active window use <tt>:q</tt>, just as you would to close a
window normally.</p>
<p>You can reduce/enlarge the size of the current window with
<kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>w</kbd>+<kbd>-</kbd></kbd> and
<kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>w</kbd>+<kbd>+</kbd></kbd>, respectively. To
specify the size of a window when you open it, prefix the <tt>:split</tt>
command with the desired height/width in lines. For example, to show
<tt>README</tt> in a window of 5 lines high: <tt>5 :split README</tt>.</p>
<h4>Discussion</h4>
<p>The default behaviour of both <tt>:split</tt> and <tt>:vsplit</tt> is to
show the current file twice. This is more useful than it may first sound.</p>
<p>When working with long documents it means that you can view the top and
bottom of the file simultaneously. If you use <a
href="#navigating-folds"><i>folding</i></a> you can use one window to
display an outline of a document while editing a specific section in another.
For example, when I'm working on reports I use <tt>:30 :vsplit</tt> to view
the first and second level headings along the left of the screen, while
editing the report in the main window.</p>
<p>By default the windows will scroll independently of each other. If you
<tt>:set scrollbind</tt> before you split the screen the windows scroll
together.</p>
Jump to Line
Something went wrong with that request. Please try again.