<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Ivan Idris Blog &#187; vim</title>
	<atom:link href="http://ivanidris.net/wordpress/index.php/tag/vim/feed" rel="self" type="application/rss+xml" />
	<link>http://ivanidris.net/wordpress</link>
	<description>Author of NumPy Beginner&#039;s Guide</description>
	<lastBuildDate>Sun, 05 Feb 2012 09:41:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Vim 7.3 released</title>
		<link>http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released</link>
		<comments>http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released#comments</comments>
		<pubDate>Sun, 22 Aug 2010 18:49:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[editors]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released</guid>
		<description><![CDATA[Breaking news Vim 7.3 has been released. Hooray, vim users rejoice! It has been two years, so it is about time for an upgrade.
Change log
The new features are

Persistent undo and undo for reload
Blowfish encryption, encryption of the swap file
Conceal text
Lua [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released" data-url="http://bit.ly/u7kaui" data-text="Vim 7.3 released" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>Breaking news <a href="http://www.vim.org/">Vim 7.3</a> has been released. Hooray, vim users rejoice! It has been two years, so it is about time for an upgrade.</p>
<h3>Change log</h3>
<p>The new features are</p>
<ul>
<li>Persistent undo and undo for reload</li>
<li>Blowfish encryption, encryption of the swap file</li>
<li>Conceal text</li>
<li>Lua interface</li>
<li>Python 3 interface</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>help version<span style="color: #000000;">-</span><span style="color: #000000; font-weight:bold;">7.3</span></pre></td></tr></table></div>

<p> offers more detailed information. So I downloaded the latest version of <a href="http://code.google.com/p/macvim/">MacVim</a> and installed vim with <a href="http://www.macports.org/">MacPorts</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">vim</span></pre></td></tr></table></div>

<p>I checked the enabled features with <b>:version</b> and </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #660033;">--version</span></pre></td></tr></table></div>

<p>I noticed that the Python 3 and Lua interface are disabled.</p>
<h3>Undo persistence</h3>
<p>Undo persistence is a new vim feature. You can find information about undo persistence with </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>help undo<span style="color: #000000;">-</span>persistence</pre></td></tr></table></div>

<p>In my .vimrc I put these lines</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">set</span> undofile
<span style="color: #804040;">set</span> undodir=<span style="color: #000000;">/</span>tmp<span style="color: #000000;">/</span>undos</pre></td></tr></table></div>

<p>The first line turns on undo persistence, which is off by default. The second line specifies a directory where to store the undo files, otherwise vim would use the same directory where the edited file is.</p>
<h3>Bag of tips and tricks (pre 7.3)</h3>
<p>My bag of vim gems and tidbits is full of stuff I would like to share no matter what. I admit that the usefulness varies and some of this stuff you may never ever need.</p>
<h3>XML folding</h3>
<p>I think that XML folding is a really neat feature. The <a href="http://www.vim.org/scripts/script.php%3Fscript_id%3D301">xmledit vim plugin</a> lets you do this the easy way. Download the plugin, put it in the .vim/ftplugin directory and add these lines to .vimrc</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>xml_syntax_folding=<span style="color: #000000; font-weight:bold;">1</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">FileType</span> xml <span style="color: #804040;">setlocal</span> <span style="color: #668080;">foldmethod</span>=<span style="color: #804040;">syntax</span></pre></td></tr></table></div>

<p>If you open a XML file, it will be folded already. You can close and open folds with <b>zo</b> and <b>zc</b>.</p>
<h3>Save a file with sudo</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>w <span style="color: #000000;">!</span>sudo tee <span style="color: #000000;">%</span></pre></td></tr></table></div>

<p>The ! calls an external command &#8211; in this case tee. % is the vim register containing the name of the file.</p>
<h3>Encoding files</h3>
<p>Vim allows you to encode data with a password</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #660033;">-x</span> secretfile</pre></td></tr></table></div>

<p>Now vim asks you to enter an encryption key also known as a password and then you need to repeat it. Next time you try to open this file you will be prompted for your password. Of course, if you try viewing the file with other editors or cat for example, you will only see gibberish.</p>
<h3>MySQL shell vi mode</h3>
<p>I tested this under Ubuntu only, but in theory it should work on other operating systems as well. Apparently if MySQL is compiled with readline support, you can set vi mode for the MySQL CLI. Add this line to ~/.inputrc</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> keymap <span style="color: #c20cb9; font-weight: bold;">vi</span> 
<span style="color: #000000; font-weight: bold;">set</span> editing-mode <span style="color: #c20cb9; font-weight: bold;">vi</span></pre></td></tr></table></div>

<h3>Vim questions on Stack Overflow</h3>
<p>I assembled a list of vim questions on Stack Overflow. The answers contain lots of useful tips and ideas. I highly recommend going through them. The signal to noise ratio is really good.</p>
<ul>
<li><a href="http://stackoverflow.com/questions/21725/favorite-gvim-plugins-scripts">Favorite vim plugins</a></li>
<li><a href="http://stackoverflow.com/questions/826208/making-vim-ubiquitous">Making vim ubiquitous</a> apparently evince let you use hjkl as well</li>
<li><a href="http://stackoverflow.com/questions/164847/what-is-in-your-vimrc">What is in your vimrc</a></li>
<li><a href="http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about">The dark corners of vim</a></li>
<li><a href="http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim">Most productive shortcut with vim</a></li>
</ul>
<h3>Random links of interest</h3>
<p>As a free service here are some interesting links</p>
<ul>
<li><a href="http://www.riptano.com/blog/slides-and-videos-cassandra-summit-2010">Cassandra Summit 2010</a></li>
<li><a href="http://superuser.com/questions/52483/terminal-tips-and-tricks-for-mac-os-x">Terminal Tips and Tricks For Mac OS X</a></li>
<li><a href="http://www.ibm.com/developerworks/aix/library/au-vitips.html">vi tips and tricks</a></li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2010%2F08%2F22%2Fvim-7-3-released&amp;title=Vim%207.3%20released" id="wpa2a_2"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2010/08/22/vim-7-3-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharpen the Vim saw</title>
		<link>http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw</link>
		<comments>http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:45:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[editors]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw</guid>
		<description><![CDATA[7 habits for effective text editing 2.0 is the title of the Google tech talk given by Bram Moolenaar on 13 February 2007.

 

The title is loosely based on the book by Stephen Covey. The actual presentation was over in [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw" data-url="http://bit.ly/tLxCyC" data-text="Sharpen the Vim saw" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div></div><p><a href="http://www.moolenaar.net/habits.html">7 habits for effective text editing 2.0</a> is the title of the <a href="http://video.google.com/videoplay?docid=2538831956647446078">Google tech talk</a> given by <a href="http://www.moolenaar.net/">Bram Moolenaar</a> on 13 February 2007.</p>
<div align="center">
<embed id="VideoPlayback" src="http://video.google.com/googleplayer.swf?docid=2538831956647446078&#038;hl=nl&#038;fs=true" style="width:400px;height:326px" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"> </embed>
</div>
<p>The title is loosely based on the book by <a href="http://www.stephencovey.com/">Stephen Covey</a>. The actual presentation was over in about 40 minutes and then it was time for questions &#8211; also about 40 minutes. The talk started a bit slow, but after making a few <a href="http://www.vim.org/">Vim</a> versus <a href="http://www.gnu.org/software/emacs/">Emacs</a> jokes the pace increased.</p>
<p>First the speaker listed the 3 steps one has to follow to make every habit work.</p>
<ol>
<li>detect inefficiency</li>
<li>find quicker way</li>
<li>make it a habit</li>
</ol>
<p>After that the slides were about the 7 vim habits. Obviously, there was too much information for a blog, but there were a few gems, I feel obliged to share. </p>
<h3>Habit 1 Moving around quickly</h3>
<p>First of all use the <b>h</b>, <b>j</b>, <b>k</b> and <b>l</b> keys &#8211; not the cursor keys. If you can touch type this makes much more sense, because these keys are on the home row and are therefore easy to reach. Many people in IT cannot type, which is surprising knowing that this is an essential part of the day to day work. Luckily, it is very easy to learn. All you need is a simple computer program and thirty minutes a day for a few weeks.</p>
<p>As a programmer I need to change code very often. For instance, to change the name of a function or variable. Basically, what was described in the video was a kind of <a href="http://help.eclipse.org/stable/topic/org.eclipse.jdt.doc.user/reference/preferences/java/editor/ref-preferences-mark-occurrences.htm">Mark Occurrences</a> feature as available in <a href="http://www.eclipse.org/">Eclipse</a>.</p>
<p>:set <a href="http://vimdoc.sourceforge.net/htmldoc/options.html">hlsearch</a> highlights whatever you are looking for. Preferably you should have this in your <b>.vimrc</b> file. You can then use * to find occurrences. This is also a vim tip &#8211; I think also referred to as the &#8220;super star&#8221; operator. <b>:nohlsearch</b> removes the highlighting. In Eclipse you have an on/off button for Mark Occurrences. Personally I find the vim way a bit confusing. I don&#8217;t know if other people feel the same way, if so maybe we should do an enhancement request <img src='http://ivanidris.net/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  . The last step is to set the <a href="http://www.linuxjournal.com/article/3805">incsearch</a> option.</p>
<p>I am not a big fan of marks, however I found a vim plugin that visualizes marks in a very convenient way. <a href="http://www.vim.org/scripts/script.php?script_id=152">ShowMarks</a> is a vim plugin that places a sign in the leftmost column of the buffer. The sign indicates the label of the mark and its location. This means that you do not need to remember where your marks were and as a bonus the default marks made by vim are also visualized. By default the following key mappings are defined:</p>
<ul>
<li>\mt : Toggles ShowMarks on and off.</li>
<li>\mh : Hides an individual mark.</li>
<li>\ma : Hides all marks in the current buffer.</li>
<li>\mm : Places the next available mark.</li>
</ul>
<p>The plugin is installed by simply unzipping showmarks.zip into the $HOME/.vim or $HOME/vimfiles folder. Signs support has to be enabled, otherwise you get a warning when you start vim. ShowMarks worked with <a href="http://code.google.com/p/macvim/">MacVim</a> immediately, however not on the command line with Terminal. I found out that you need to compile vim with the (big or huge) switch. If you have <a href="http://www.macports.org/">MacPorts</a> installed, you can execute</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> +huge +python</pre></td></tr></table></div>

<p>The python switch is needed for the <a href="http://www.vim.org/scripts/script.php%3Fscript_id%3D1953">vimpress plugin</a> from my <a href="http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim">previous post</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">port info <span style="color: #c20cb9; font-weight: bold;">vim</span></pre></td></tr></table></div>

<p>gives the following variants</p>
<pre>
Variants:    athena, big, cscope, gtk1, gtk2, huge, motif, nls, perl,
             puredarwin, python, ruby, small, tcl, tiny, universal,
             xim
</pre>
<p>Tiny means that most features are disabled, then in increasing order of features enabled you have small, big and huge. Probably huge also includes python support. The MacPorts vim variant that I have now does not give a warning or error anymore, however instead of a mark I see a blue square.</p>
<div align="center">
   <a href="http://ivanidris.net/images/wordpress/feb09/TerminalShowMarks.png" rel="lightbox"/><br />
      <img src="http://ivanidris.net/images/wordpress/feb09/TerminalShowMarksThumb.png" width="240" height="180"/><br />
   </a>
</div>
<p>The xterm terminal that comes with the Mac X11 application does not have this problem. Unfortunately I have been using the Terminal application more often for aesthetic reasons.</p>
<h3>Habit 2 Don&#8217;t type it twice</h3>
<p>Typing the same thing over and over again costs energy, time and is of course boring. My favorite command, the dot command, makes life a lot easier. <b>Ctrl N</b> or <b>Ctrl P</b> does insert mode completion, so you can type a few characters and then let vim complete the word. This is especially useful when you need to write a long and hard to remember method name.</p>
<p>This might seem obvious, but you can avoid a lot of typing by copy pasting or cut and paste. The good thing about vim is that you can do this really efficiently without using a mouse. You can, for instance, select a block in visual mode and paste it somewhere else or delete a line with <b>dd</b> and put it where you need it.</p>
<p>Sometimes you need to repeat a certain sequence of commands. In such cases you can record a macro. The usage is very similar to marks. <b>qa</b> records a macro, which then can be executed with <b>@a</b>. Unfortunately, it is quite hard to get this right. I tend to keep my macros short and simple. Still it seems that there are not many opportunities to record macros.</p>
<h3>Habit 3 Fix it when it&#8217;s wrong</h3>
<p>Stephen Covey&#8217;s third principle is called &#8220;<a href="http://phoneboy.vox.com/library/post/habit-3-put-first-things-first.html">Put first things first</a>&#8220;. With a bit of imagination you can equate it to &#8220;Fix it when it&#8217;s wrong&#8221;. So put fixing errors first. In the talk this was mainly about spelling and the spelling checker in vim. The advice was to create a list of spelling mistakes and make vim automatically correct them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>abbr teh the</pre></td></tr></table></div>

<p>was the example given in the talk. My most common mistake is writing &#8220;taht&#8221; instead of &#8220;that&#8221;. At least that is what I catch myself typing in <a href="http://www.skype.com/">Skype</a> frequently. <a href="http://www.skype.com/">Skype</a> as far as I know does not have any vi key bindings or tabs for that matter. Another enhancement request is emerging <img src='http://ivanidris.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p>I find the spellchecker in vim quite useful. <b>:help spell</b> displays the relevant help page. <b>]s</b> shows the next error, <b>[s</b> the previous one and <b>zg</b> adds the word to the dictionary. <b>z=</b> gives suggestions from the dictionary &#8211; to get out of the suggestions list type <b>Ctrl C</b>.</p>
<h3>Habit 4 A file seldom comes alone</h3>
<p>An analogy with Covey&#8217;s fourth <a href="http://phoneboy.vox.com/library/post/habit-4-think-winwin.html">&#8220;Win/Win&#8221; principle</a> is completely missing here. Also I am not too keen on the whole &#8220;Win/Win&#8221; concept. Maybe I feel that way because as a chess player I translate &#8220;Win/Win&#8221; to a draw. A draw is no good usually, unless you are in a tournament situation, where you are ahead in points.</p>
<p>As a developer you tend to work on projects, that is why IDE&#8217;s as Eclipse are so project minded. Projects consist of multiple file, such as source code files, configuration files, all kinds of resource files, documentation etcetera etcetera. Vim does not have the notion of project as far as I know, but still lets you work on a group of related files easily. In a <a href="http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim">previous post</a> I already mentioned using tags files and the <a href="http://vim-taglist.sourceforge.net/">TagList plugin</a>.</p>
<div align="center">
   <a href="http://ivanidris.net/images/wordpress/feb09/TagList.png" rel="lightbox"><br />
      <img src="http://ivanidris.net/images/wordpress/feb09/TagListThumb.png" width="240" height="180"/><br />
   </a>
</div>
<p>In the talk <a href="http://www.a-a-p.org/agidetutor.html">Agide</a> is mentioned. This is an old project also from the creator of vim promising to bring us an IDE based on vim. You can create projects or debug your code with gdb. Most operations are performed by mouse just as in conventional IDE&#8217;s. Personally I don&#8217;t like Agide&#8217;s GUI &#8211; it is ugly. Projects can be build from Agide, but you still have to save your program before building. Not as convenient as Eclipse.</p>
<h3>Habit 5 Let&#8217;s work together</h3>
<p>About the communication between vim and other applications like for instance Word. The trick for copying to and from Word is to have</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span><span style="color: #804040;">set</span> <span style="color: #668080;">tw</span>=<span style="color: #000000; font-weight:bold;">0</span> <span style="color: #668080;">wrap</span> <span style="color: #668080;">linebreak</span></pre></td></tr></table></div>

<p><a href="http://www.eclipse.org/">Eclipse</a> apparently has a too complex interface to let it work together with vim. I am using a commercial plugin that kind of offers a very basic vim functionality subset. <a href="http://eclim.sourceforge.net">Eclim</a> was not mentioned in the talk, but I feel I should say something about it, because it looks very promising. The features include Javascript, Python and Maven support. Three scenarios are described on the Eclim website:</p>
<ol>
<li>You run a headless instance of Eclipse which all vim instances can then connect to.</li>
<li>You run the Eclim server inside of the Eclipse GUI and then interact with it via external vim instances.</li>
<li>The same as the second scenario, but here gvim is used as embedded eclipse editor.</li>
</ol>
<p>At first I was only aware of the first scenario, which seemed a bit limited, but now I will definitely give Eclim a shot. I am just wondering, whether I can use MacVim as well. Also I am not so clear on the Eclipse and vim plugins situation.</p>
<p>Older version of <a href="http://msdn.microsoft.com/vstudio/">MS visual studio</a> supported vim and I know at least one commercial plugin, that seems to do the job with the latest version of Visual Studio. According to Bram Moolenaar &#8211; <a href="http://www.mutt.org/">Mutt</a> and <a href="http://www.sniff-em.com/">Sniff</a> support vim out of the box.</p>
<h3>Habit 6 Text is structured</h3>
<p>I find this a bold statement. Text does not need to be structured although it usually is. The structured text that this habit refers to will have some kind of structure that can be used to our advantage. In programming there is the edit, compile, test cycle. Not necessarily test driven. When I was in university we did not have fancy IDE&#8217;s as Eclipse. We would run commands like gcc from the command line. You would then get error messages in the console with line numbers, which were not always correct by the way. Later I worked with MS Visual Studio, I did not find it very user friendly, however. The point is that it was very cumbersome to have to remember the line number where something was wrong and then go back to the source file for editing. In the vim world, a program can be compiled with <b>:make</b>. <b>:clist</b> lists compile errors and <b>:cnext</b> and <b>:cprevious</b> move through the errors.</p>
<p>There are thousands of vim plugins available that can deal with all kinds of files. In order to handle a new type of file, one can write a small program in several scripting languages, including a small language created specifically for vim. I read lately a bit about the vim scripting language. It appears, that this language at least on the surface looks like Python. There are some object oriented features and exception handling. If you get ambitious, you could even write your own libraries.</p>
<p>I made a small plugin for myself to help me blogging. It gives me the ability to find a suitable link, for something, that I am writing about. All I have to do is select a phrase I want to search for and yank it into the unnamed register. You can check the contents of the registers using <b>:registers</b>. Then I will call my special script with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span><span style="color: #804040;">execute</span> GoogleLink<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>This will magically insert the first relevant link that the Google AJAX service can find. Here is the code, use at your own risk:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">function<span style="color: #66cc66;">!</span> GoogleLink<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
python <span style="color: #66cc66;">&lt;&lt;</span> EOF
<span style="color: #ff7700;font-weight:bold;">import</span> vim, <span style="color: #dc143c;">urllib</span>
&nbsp;
query = vim.<span style="color: #008000;">eval</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;@<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: black;">&#41;</span>
url = <span style="color: #483d8b;">&quot;http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q=&quot;</span> + <span style="color: #dc143c;">urllib</span>.<span style="color: black;">quote_plus</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span>
handle = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>
searchResult = handle.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
commaSeparatedList = searchResult.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
&nbsp;
link = <span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> commaSeparatedList:
   <span style="color: #ff7700;font-weight:bold;">if</span> i.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;url&quot;'</span><span style="color: black;">&#41;</span>:
      i = i.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;url&quot;:'</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
      link = i.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;'</span>, <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
vim.<span style="color: black;">current</span>.<span style="color: black;">line</span> = vim.<span style="color: black;">current</span>.<span style="color: black;">line</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>query, <span style="color: #483d8b;">'&lt;a href=&quot;'</span> + link + <span style="color: #483d8b;">'&quot;&gt;'</span> + query + <span style="color: #483d8b;">'&lt;/a&gt;'</span><span style="color: black;">&#41;</span>
&nbsp;
EOF
endfunction</pre></td></tr></table></div>

<p>As you can see the plugin is still in the prototype stage. It seems to work, but I haven&#8217;t tested it thoroughly and the feature set is limited.The <a href="http://en.wikipedia.org/wiki/AJAX">AJAX</a> service produces <a href="http://json.org/">JSON</a> for the search results. A snippet of the TCP stream dump:</p>
<pre>
GET /ajax/services/search/web?v=1.0&#038;q=Ivan+Idris HTTP/1.0
Host: ajax.googleapis.com
User-agent: Python-urllib/1.15

HTTP/1.0 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Type: text/javascript; charset=utf-8
X-Embedded-Status: 200
X-Content-Type-Options: nosniff
Content-Length: 3134
Server: GFE/1.3
Connection: Close

{"responseData":
   {"results":
      [{"GsearchResultClass":"GwebSearch",
      "unescapedUrl":"http://ivanidris.net/",
      "url":"http://ivanidris.net/",
      "visibleUrl":"ivanidris.net" ...
</pre>
<p>The Python JSON module was introduced in Python 2.6. However, MacVim 7.2 is compiled with Python 2.3 for backwards compatibility with <a href="http://en.wikipedia.org/wiki/Mac_OS_X_v10.4">Tiger</a>. It is possible to recompile MacVim with higher version Python support, but it is a bit of a hassle. Luckily, I didn&#8217;t really need full blown JSON capability. Instead I just did some simple string manipulation.</p>
<h3>Habit 7 Sharpen the saw</h3>
<p>The presenter explained, how to slowly, but surely get better at using vim, by continually finding improvements and making them a habit. You need to take the time, do it step by step &#8211; repetition is key. Repeat after me <img src='http://ivanidris.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . <a href="http://www.profitadvisors.com/7thhabit.shtml">Sharpening the saw</a> can be done by  searching the documentation using <b>:h</b> or <b>:helpgrep</b>, subscribing to mailing lists and RSS feeds or searching newsgroups. Here is a list of vim related feeds I have been reading recently:</p>
<ul>
<li><a href="http://dailyvim.blogspot.com/feeds/posts/default">Daily vim</a></li>
<li><a href="http://stackoverflow.com/feeds/tag/vim">Questions tagged &#8216;vim&#8217; &#8211; Stack Overflow</li>
<li><a href="http://www.vim.org/tips/rss2.php">Vim tips</a></li>
<li><a href="http://www.reddit.com/r/vim/.rss">Vim links on Reddit</a></li>
</ul>
<p>You can also join the IRC #vim channel at <a href="http://freenode.net/">Freenode</a>. If you have a Mac, I suggest downloading <a href="http://colloquy.info/">Colloquy</a>. Together with <a href="http://growl.info/">Growl</a> it makes an awesome combination. Also recommended for iPhone users.</p>
<p>The <a href="http://vimdoc.sourceforge.net/htmldoc/usr_toc.html">vim user manual</a> can be found at the <a href="http://vimdoc.sourceforge.net/">Vimdoc</a> website. From the video I learned that the user manual was originally based on the book &#8220;Vi IMproved &#8211; Vim&#8221; by Steve Oualline. This book described the features in vim 5.7. The user manual has been updated for the most recent vim version. In fact, I read Steve Oualline&#8217;s book and recently also the <a href="http://vimdoc.sourceforge.net/htmldoc/usr_toc.html">vim user manual</a> and to me they seem completely different documents. In my opinion, they are complementary and you can read them both. The book has a larger number of pages and has diagrams. The user manual is on the other hand, as I said, up to date and written by Bram Moolenaar himself, as far as I can tell. Another interesting resource is the wiki book <a href="http://www.swaroopch.com/notes/Vim">&#8220;Byte of vim&#8221;</a>. It has many useful links and information on plugins.</p>
<p>Google can find several vim cheat sheets. At work I have set the <a href="http://www.viemu.com/vi-vim-cheat-sheet.gif" rel="lightbox">vim graphical cheat sheet</a> as my wallpaper.</p>
<p>The neat thing is that the keyboard image has its keys mapped to vim commands. This, combined with the pretty colors, makes it visually appealing and also a great touch typing learning aid. As an added bonus, I also have something to talk about when somebody is staring at my desktop. I remember somebody saying that there is also a graphical Emacs cheat sheet. I think that was a joke, because you cannot possibly visualise Emacs key bindings in this way.</p>
<h3>Conclusion</h3>
<p>At this point, I have written more than the equivalent of a hundred <a href="http://en.wikipedia.org/wiki/Twitter">tweets</a>. This is more characters than in my <a href="http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim">first attempt</a>. So this writeup was based on a video, which in turn was based on a book. In any case I got the opportunity to structure my text better and apply the principle of <a href="http://en.wikipedia.org/wiki/Chunking_(psychology)">chunking</a> ( not one of the seven habits <img src='http://ivanidris.net/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). It turns out that I don&#8217;t have enough material for a vim article series trilogy currently. Next time I will keep it simple and blog about my <a href="http://code.google.com/appengine/">Google App Engine</a> experiments &#8211; a deadly mix of Python and <a href="http://www.adobe.com/products/flex/">Flex</a>. Ladies and gentlemen, I hereby declare the comments section open!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2009%2F02%2F03%2Fsharpen-the-vim-saw&amp;title=Sharpen%20the%20Vim%20saw" id="wpa2a_4"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2009/02/03/sharpen-the-vim-saw/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>All things Vi(m)</title>
		<link>http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim</link>
		<comments>http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim#comments</comments>
		<pubDate>Thu, 08 Jan 2009 20:25:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[editors]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=11</guid>
		<description><![CDATA[This is my first post on my own blog, website and domain. I did the famous 5 minutes WordPress install, which in my case took a bit longer. Of course, these are ideal minutes, but still it was pretty easy. [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-left"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim" data-url="http://bit.ly/vrrhzt" data-text="All things Vi(m)" data-count="vertical" data-via="socializeWP" ><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-left"><iframe src="http://www.facebook.com/plugins/like.php?href=http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div></div><p>This is my first post on my own blog, website and domain. I did the famous 5 minutes WordPress install, which in my case took a bit longer. Of course, these are ideal minutes, but still it was pretty easy. As this is my first try &#8211; I am expecting that this will be my best or possibly my worst post ever. Anyway I am planning for it to be the longest entry. I hope that this at least succeeds.</p>
<p>A little tidbit of background information about myself. I was born in Bulgaria. My parents are from Indonesia and genetically speaking I am Indonesian. We moved to the Netherlands when I was thirteen years old. I have a Dutch passport went to a Dutch highschool and university. The point I want to make is, that my English to put it mildly is far from perfect. Please keep that in mind, while you are reading.</p>
<p>There are many topics worthy of a post, but it was <a href="http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim">Jamis Buck&#8217;s announcement</a> that he is switching back from Textmate to Vim, that helped me make up my mind. I have been using vi(m) for longer than 10 years, first reluctantly, than with hesitation and now &#8230; I don&#8217;t know exactly. I would say something resembling love.</p>
<p>The funny thing is, that once you learn the system and have a decent typing speed you can become addicted to vi. Even stranger is the fact, that nobody uses more than a subset of the complete functionality available. The main reason being that it takes time to get used to this type of editing. If I am allowed to do a comparison with other editors &#8211; still vi(m) will be #1 for me. For instance, the other &#8220;old&#8221; Unix editor. You know starts with E and rhymes with wax. Just for fun let&#8217;s compare some of the commands, not including the obvious winner commands on the home row.</p>
<p>Yes, the famous <a href="http://www.emacswiki.org/emacs/ViEmacsTable">ViEmacsTable</a>. So you have 3 options basically, get RSI, use another editor or use viper mode. Just kidding. I tried using viper mode, just in Terminal on my Mac laptop, but I could not figure out, where the Meta key is. Probably have to hold the fn key.</p>
<p>Back to the famous switcher. His claim is that you can use vim as an IDE or at least replace Textmate. I don&#8217;t know anything about Textmate, except that it is apparently really cool. Cool with at least 5 o&#8217;s. I do know a bit about Eclipse, less about Netbeans and almost nothing about IntelliJ. It is very likely, that I have played around with other IDE&#8217;s, but I just can&#8217;t remember. Oh yeah, I forgot Visual Studio. Used it for my last project in university. In retrospect, should have used a plain text editor with makefiles. </p>
<p>Would a Java programmer use vi(m) instead of Eclipse? No. Why? Lack of code completion, refactoring and all the other options. Well, there is <a href="http://eclim.sourceforge.net/">eclim</a> that should help with a lot of these shortcomings. Unfortunately, I did not have time to try it out, but still I haven&#8217;t heard of anybody actually using eclim and I am pretty sure I would not even be allowed at work. Still I think that with the proper setup vim is the better choice for other languages, mostly dynamic languages. Myself, I cheat a bit, I use a special Eclipse plugin (not free but cheap, don&#8217;t want to give you the details but it is easy enough to google). It supports a large portion of the subset of commands I use. Right from Eclipse, which is a bit of a hassle especially with pair programming, because it involves clicking the &#8220;vi disable button&#8221; and apologizing after unsuccessful editing attempts.<br />
According to my analysis blogging about vim requires the following ingredients: favorite commands, plugins, settings in .vimrc and less familiar commands, which now prove useful. First things, first, favorite commands. Obviously, hjkl basic movement, dd and D deleting lines, dw and cw words editing, f jump to character, the dot command. I have the tendency to delete more than change, even if changing is the better option. Also tend to use dot instead of a number in a command, mostly because I cannot be bothered to count the number of lines in a dd command. It is easier to just hold down, the dot key for a while. gg for going to the first line, G to the last. yy for line yanking, p and P for pasting. q for macros. I don&#8217;t use macros that often, but sometimes it seems easier to use a macro, instead of writing a script.</p>
<p>Vim can be extended using plugins. Some plugins can really help you to replace IDE features. This command</p>
<pre>
:helptags ~/.vim/doc
</pre>
<p>updates the documentation to include information about your installed plugin.</p>
<p>The <a href="http://www.vim.org/scripts/script.php?script_id=1658">NERDTreePlugin</a> is the one that I use the most. It is a file system browser in vi style, which means that you can navigate through directories without using a mouse. I hope that somebody makes something like that for Eclipse.</p>
<p>The installation is easy and similar to other vim plugins. Just download and unzip in your ~/.vim directory.</p>
<p>I made a special mapping for the F3 key in ~./vimrc to toggle the navigator on the left.</p>
<pre>
map <F3> :execute 'NERDTreeToggle ' . getcwd()<CR>
</pre>
<p>NERDTreePlugin comes with its own commands. Here is a list of the ones I use most of the time.</p>
<ul>
<li>H shows/hides hidden files</li>
<li>t opens in new tab</li>
<li>o opens node</li>
</ul>
<p>The cycle windows command Ctrl W Ctrl W switches between editor and navigator</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=273">TagList</a> is a handy plugin for coding. It shows tags as the eclipse outline. TagList requires ExuberantCtags. ExuberantCtags warrants a more detailed explanation. Although my Mac comes with ctags, I could not use it, which is annoying, but on the other hand it cannot even tell you the version number. The generic way to install ExuberantCtags is , downloading it and compiling:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>superb-west.dl.sourceforge.net<span style="color: #000000; font-weight: bold;">/</span>sourceforge<span style="color: #000000; font-weight: bold;">/</span>ctags<span style="color: #000000; font-weight: bold;">/</span>ctags-<span style="color: #000000;">5.7</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf ctags-<span style="color: #000000;">5.7</span>.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> ctags-<span style="color: #000000;">5.7</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>The binary is then placed in /usr/local/bin/ctags. If you have MacPorts installed (which I have) do:</p>
<pre>
sudo port install ctags
</pre>
<p>the binary is then placed in /opt/local/bin/ctags. From vim you can then type</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #7a0874; font-weight: bold;">cd</span> project_root
:<span style="color: #000000; font-weight: bold;">!</span>ctags <span style="color: #660033;">-R</span> .
:<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">tags</span>=tags</pre></td></tr></table></div>

<p>Back to TagList. Again just unzip in your ~/.vim directory.  These are my settings in .vimrc for TagList. They point to my ctags binary from MacPorts, mapped to the T key. Window is on the right. By default &#8211; the tag list is shown on the left, but I prefer to have only the NERDTree there. Anyway the window can be rotated to another spot by Ctrl &#8211; W r.</p>
<pre>
let Tlist_Ctags_Cmd='/opt/local/bin/ctags'
let Tlist_Use_Right_Window = 1
map T :TlistToggle<CR>
</pre>
<p>Ctrl W h or l,switches to the left or right window. j and k scroll in the taglist window, pressing Enter on a method navigates to its definition.You can browse help with</p>
<pre>
:help taglist and :help taglist-intro
</pre>
<p>Vimpress is the plugin that I am now using to write my blog. I am still evaluating it so I cannot say too much about it.</p>
<p>It has the following commands:</p>
<ul>
<li>“:BlogList” Lists all articles in the blog</li>
<li>“:BlogNew” Opens page to write new article</li>
<li>“:BlogOpen id” Opens the article for edition</li>
<li>“:BlogSend” Saves the article to the blog</li>
</ul>
<p>There is a blog.vim file in the plugin directory, where you need to setup your login details. On the first test run with :BlogSend, vimpress told me that &#8220;An error occurred&#8221;. So I had to analyse the network log with Wireshark. Wireshar used to be called Ethereal and is a packet sniffer with a nice GUI. The Macports Wireshark I have installed doesn&#8217;t look that nice though. What I typically do, is capture some network traffic and then do a filter with &#8220;tcp contains [search phrase]&#8220;. I will then &#8220;Follow the TCP stream&#8221; on the filtered packets. Below is the result with some minor edits.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;methodResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;struct<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;member<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>faultCode<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;int<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>405<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/int<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/member<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;member<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>faultString<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>XML-RPC services are disabled on this blog. An admin user can enable them at ....wordpress/wp-admin/options-writing.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/member<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struct<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/methodResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Apparently you have to enable XML-RPC services to get this to work. Also I noticed that by default vimpress doesn&#8217;t give the blog a title. A Meta header is generated where you can specify the title. The other fields in the header should be left blank, I believe.</p>
<p>Blog.vim is written in Python, so I added a bit of error handling and now if I change the url settings for WordPress, and do :BlogList I get:</p>
<pre>
A protocol error occurred
URL: ivanidris.net/invaliddir/xmlrpc.php
HTTP headers: Date: Mon, 05 Jan 2009 16:38:29 GMT
Server: Power MOD by myhost.net
Connection: close
Content-Type: text/html; charset=iso-8859-1
Error code: 404
Error message: Not Found
</pre>
<p>What I changed was to add an exception handler in blog_list_posts():</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">xmlrpclib</span>.<span style="color: black;">ProtocolError</span>, err:
    onProtocolError<span style="color: black;">&#40;</span>err<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Of course you can do this for the other methods as well, this is left as an exercise to the reader <img src='http://ivanidris.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> onProtocolError<span style="color: black;">&#40;</span>err<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;A protocol error occurred&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;URL: %s&quot;</span> <span style="color: #66cc66;">%</span> err.<span style="color: black;">url</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;HTTP headers: %s&quot;</span> <span style="color: #66cc66;">%</span> err.<span style="color: black;">headers</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error code: %d&quot;</span> <span style="color: #66cc66;">%</span> err.<span style="color: black;">errcode</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error message: %s&quot;</span> <span style="color: #66cc66;">%</span> err.<span style="color: black;">errmsg</span></pre></td></tr></table></div>

<p>Vim features I do not use that often include folding and markers. As a matter of fact I don&#8217;t use folding in Eclipse much either. I had a brief look in :help folding. The usage pattern is: step 1 define a fold method. For instance :set foldmethod=indent. zo opens, zc closes folds and za does both (alternates). Markers are created with m and then a letter in upper or lowercase, for example ma. You can jump back with &#8216;a or `a. Personally I find this cumbersome, but hey that is what vim does to you. I guess if you execute a command a hundred times, these kind of feelings disappear.</p>
<p>Now onto .vimrc, which if you did not know is the configuration file for vim. It is a very important file, there are even special websites, where people post their .vimrc. I am not going to do that here, but merely show the bits that I think are interesting. First, most importantly indentation, which of course is crucial if you program in Python. The settings shown below are apparently according to the Python style guide. I haven&#8217;t checked I am embarrassed to say.</p>
<pre>
set sts=3
set smarttab
set shiftwidth=3
set autoindent
set expandtab
set backspace=start,indent
</pre>
<p>Then there are the setting, which further help with coding. I have similar settings in Eclipse.</p>
<pre>
set number
set ruler
set hlsearch
syntax on
</pre>
<p>Line numbering, highlighted searching and syntax coloring is what it is supposed to do. Ruler too.</p>
<p>Spellchecking is a new feature in Vim 7, as far as I know. If you have it on, all your errors get underlined. Here for met it is a red dotted line for spelling mistakes and blue for grammar.</p>
<pre>
map <Leader>se :setlocal spell spelllang=en_us<CR>
map <Leader>sn :setlocal nospell<CR>
</pre>
<p>If I do backslash se, all my code and the vim commands are underlined. I can turn it off with backslash sn, if I want to, but for blogging it is perfect. One warning, you have to press the s quickly after the backslash, otherwise vim will only register the s command and you will go into insert mode.</p>
<p>My screen resolution is set to 1680 to 1050. For me, small fonts are unreadable so I have set my font on the MacVim to 18 by default.</p>
<pre>
set guifont=Monaco:h18
</pre>
<p>Why I use MacVim? Well, it is a &#8220;real&#8221; Mac application and you can use it in full screen mode (Cmd Shift F), which is awesome. Also I have set it up to be an external editor, so I can edit files from Finder and other applications. In Firefox I am using the <a href="https://addons.mozilla.org/en-US/firefox/addon/4125">It&#8217;s All text</a> plugin to edit textareas with MacVim. Vimperator might have been a better choice, but font wise I don&#8217;t like it and it does weird things to the toolbars. Firefox and my Mac setup will be the topic of essays to follow. The thirteen thousand character line has been crossed already, so it is better to leave something for next time.</p>
<p>The topics I am planning to blog about include Maven 2, Python, Flex, Eclipse, Java, Groovy, Grails, shell scripts, my Google App Engine experiments and Vim again. Not necessarily in this order and not necessarily this year. Originally the plan was to submit an article each month, but realistically it might turn out to be once every two months. I hope to keep it up for at least one year. Hope to see you next time and please feel free to comment.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2009%2F01%2F08%2Fall-things-vim&amp;title=All%20things%20Vi%28m%29" id="wpa2a_6"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2009/01/08/all-things-vim/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

