<?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>mitch&#039;s meanderings &#187; gvim</title>
	<atom:link href="http://mitchcontla.com/tag/gvim/feed/" rel="self" type="application/rss+xml" />
	<link>http://mitchcontla.com</link>
	<description>thoughts on life, technology, and running; links, photos, and videos</description>
	<lastBuildDate>Wed, 19 May 2010 04:58:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Nautilus Script: Edit Remote Files (SSH) with Vim</title>
		<link>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/</link>
		<comments>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 08:11:41 +0000</pubDate>
		<dc:creator>mitch</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[nautilus]]></category>
		<category><![CDATA[nautilus-script]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://mitch.contlafamily.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/</guid>
		<description><![CDATA[My on again, off again love affair with KDE is currently off (but that&#8217;s another story). I&#8217;m once again enjoying the simplicity of Gnome, and the elegance of Nautilus. The ability to graphically browse remote servers via SSH is great, but I found out that trying to edit a remote file chokes Vim. Apparently the [...]]]></description>
			<content:encoded><![CDATA[<p>My on again, off again love affair with <a href="http://www.kde.org/" title="K Desktop Environment"><span class="caps">KDE</span></a> is currently off (but that&#8217;s another story). I&#8217;m once again enjoying the simplicity of <a href="http://www.gnome.org/" title="Gnome Desktop">Gnome</a>, and the elegance of <a href="http://www.gnome.org/projects/nautilus/" title="Nautilus file manager">Nautilus</a>.</p>

<p>The ability to graphically browse remote servers via <acronym title="secure shell">SSH</acronym> is great, but I found out that trying to edit a remote file chokes <a href="http://www.vim.org/" title="Vim editor">Vim</a>. Apparently the netrw module does not handle an <span class="caps">SSH </span><acronym title="Uniform Resource Identifier">URI</acronym>, but rather prefers <acronym title="secure copy">SCP</acronym>. So a quick nautilus-script to the rescue.</p>

<pre class="code python"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
&nbsp;
files = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> unescape<span style="color: black;">&#40;</span>uri<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\s</span>'</span>, r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\</span> '</span>, <span style="color: #dc143c;">urllib</span>.<span style="color: black;">unquote</span><span style="color: black;">&#40;</span>uri<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">getenv</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;NAUTILUS_SCRIPT_SELECTED_URIS&quot;</span>, <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^file://'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
        files.<span style="color: black;">append</span><span style="color: black;">&#40;</span>unescape<span style="color: black;">&#40;</span><span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^file://'</span>, r<span style="color: #483d8b;">&quot;&quot;</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^ssh://'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
        files.<span style="color: black;">append</span><span style="color: black;">&#40;</span>unescape<span style="color: black;">&#40;</span><span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^ssh://([^/]+)(/[^/]+){2}/(.*)$'</span>, r<span style="color: #483d8b;">'scp://<span style="color: #000099; font-weight: bold;"></span>/<span style="color: #000099; font-weight: bold;"></span>'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> files:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;gvim &quot;</span><span style="color: #483d8b;">&quot;&quot;</span> + <span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>files<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;</pre>

<p>Still some work to do, but for now it&#8217;s simple and effective.</p>]]></content:encoded>
			<wfw:commentRss>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
