<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Source Allies Blog &#187; File Wrangling</title>
	<atom:link href="http://blogs.sourceallies.com/category/development/file-wrangling/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.sourceallies.com</link>
	<description>Technical and process thinking from Source Allies employees</description>
	<lastBuildDate>Mon, 26 Jul 2010 15:01:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Vim splits, an introduction.</title>
		<link>http://blogs.sourceallies.com/2009/11/vim-splits-an-introduction/</link>
		<comments>http://blogs.sourceallies.com/2009/11/vim-splits-an-introduction/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 18:00:42 +0000</pubDate>
		<dc:creator>Scott Peshak</dc:creator>
				<category><![CDATA[File Wrangling]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blogs.sourceallies.com/?p=452</guid>
		<description><![CDATA[First off, lets get some test files:
for i in foo bar cat dog ; do echo $i &#62; $i ; done;
This creates 4 files named  foo, bar, cat and dog. Each file has a single line that contains the file&#8217;s own name.
Let&#8217;s open the first file:
vim foo

This would be the familiar vim with one file [...]]]></description>
			<content:encoded><![CDATA[<p>First off, lets get some test files:</p>
<p><code>for i in foo bar cat dog ; do echo $i &gt; $i ; done;</code></p>
<p>This creates 4 files named  foo, bar, cat and dog. Each file has a single line that contains the file&#8217;s own name.</p>
<p>Let&#8217;s open the first file:</p>
<p><code>vim foo</code></p>
<p><img class="alignnone size-full wp-image-462" title="vim with single file" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.22.38-PM.png" alt="vim with single file" width="639" height="558" /></p>
<p>This would be the familiar vim with one file open view.  Now to open a new split and open the bar file inside it:</p>
<p><code>:sp bar</code><br />
<img class="alignnone size-full wp-image-465" title="vim with two splits" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.23.49-PM.png" alt="vim with two splits" width="639" height="558" /></p>
<p>Focus is in the new split initially.  To move between splits first press Ctrl-w (I remember this by Control Window, I&#8217;m not sure what the official mnemonic is) Then press a directional key to move the cursor to the split you&#8217;re interested in.  Directional key could be the arrows or my preferred home row method.</p>
<p>We can split again and open the cat file:</p>
<p><code>:sp cat</code><br />
<img class="alignnone size-full wp-image-467" title="vim with three splits" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.25.13-PM.png" alt="vim with three splits" width="639" height="558" /></p>
<p>By now you may have noticed the every time you open new split all splits get an equal amount of screen real estate.  The size of the current split can be adjusted by using Ctrl-w + and Ctl-w &#8211; (+ increases the split size by one line, &#8211; reduces the split size by one line)  If the idea of bumping the size of the split one line at a time doesn&#8217;t sit well with you, prefix +/- with a multiplier.  For example to increase our current split (which is the cat split) by 5 lines run the following:</p>
<p><code>Ctrl-w 5+</code><br />
<img class="alignnone size-full wp-image-473" title="vim with adjusted split size" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.35.11-PM.png" alt="vim with adjusted split size" width="639" height="558" /></p>
<p>To quickly &#8220;maximize&#8221; the current split:</p>
<p><code>Ctrl-w _</code><br />
<img class="alignnone size-full wp-image-475" title="vim with 3rd split maximized" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.36.43-PM.png" alt="vim with 3rd split maximized" width="639" height="558" /></p>
<p>And to return to equalized splits:</p>
<p><code>Ctrl-w =</code><br />
<img class="alignnone size-full wp-image-467" title="vim with three splits" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.25.13-PM.png" alt="vim with three splits" width="639" height="558" /></p>
<p>So far we have only been working with horizontal splits.  Vim also supports vertical splits.  To split the current split again, only vertically (and at the same time open the file named &#8220;dog&#8221;) run:</p>
<p><code>:vsp dog</code><br />
<img class="alignnone size-full wp-image-478" title="vim with vertical split" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-4.40.31-PM.png" alt="vim with vertical split" width="639" height="558" /></p>
<p>Of course you can keep splitting until your head hurts.  Vim even allows you to split the same file multiple times and it will automatically keep the contents in sync.  This is very handy for referencing one section of a file while editing another.</p>
<p><img class="alignnone size-full wp-image-487" title="Crazy vim splits" src="http://blogs.sourceallies.com/wp-content/uploads/2009/11/Screen-shot-2009-11-13-at-5.11.54-PM.png" alt="Crazy vim splits" width="639" height="558" /></p>
<p>Split related commands:</p>
<table border="0">
<thead>
<tr>
<th>Command</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>:sp <em>filename</em></td>
<td>Open <em>filename</em> in horizontal split</td>
</tr>
<tr>
<td>:vsp <em>filename</em></td>
<td>Open <em>filename</em> in vertical split</td>
</tr>
<tr>
<td>Ctrl-w h<br />
Ctrl-w ←</td>
<td>Shift focus to split on left of current</td>
</tr>
<tr>
<td>Ctrl-w l<br />
Ctrl-w →</td>
<td>Shift focus to split on right of current</td>
</tr>
<tr>
<td>Ctrl-w j<br />
Ctrl-w ↓</td>
<td>Shift focus to split below the current</td>
</tr>
<tr>
<td>Ctrl-w k<br />
Ctrl-w ↑</td>
<td>Shift focus to split above the current</td>
</tr>
<tr>
<td>Ctrl-w <em>n</em>+</td>
<td>Increase size of current split by <em>n</em> lines</td>
</tr>
<tr>
<td>Ctrl-w <em>n</em>-</td>
<td>Decrease size of current split by <em>n</em> lines</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blogs.sourceallies.com/2009/11/vim-splits-an-introduction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
