<?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>Milton Soares Filho &#187; vim</title>
	<atom:link href="http://blog.msoares.pro.br/tags/vim/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.msoares.pro.br</link>
	<description>Random rants and SW developers' stuff</description>
	<lastBuildDate>Mon, 08 Aug 2011 16:02:28 +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>Hiding that horrible tabline in Vim</title>
		<link>http://blog.msoares.pro.br/archives/hiding-that-horrible-tabline-in-vim</link>
		<comments>http://blog.msoares.pro.br/archives/hiding-that-horrible-tabline-in-vim#comments</comments>
		<pubDate>Thu, 20 Jan 2011 04:26:52 +0000</pubDate>
		<dc:creator>milton</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.msoares.pro.br/?p=223</guid>
		<description><![CDATA[Long time no post in here, sorry. Since I&#8217;ve had the chance to review Kim Schulz&#8217;s Hacking Vim 7.2 ebook1 and a friend of mine started using vim as his main development tool, digging into Vim&#8217;s configurations and flavours has become somewhat even more pleasant. In an attempt to improve my performance when editing various [...]]]></description>
			<content:encoded><![CDATA[<p>Long time no post in here, sorry.</p>

<p>Since I&#8217;ve had the chance to review Kim Schulz&#8217;s <a href="https://www.packtpub.com/hacking-vim-7-2/book">Hacking Vim 7.2</a> ebook<sup class="footnote"><a href="#fn1">1</a></sup> and a friend of mine started using vim as his main development tool, digging into Vim&#8217;s configurations and flavours has become somewhat even more pleasant.</p>

<p>In an attempt to improve my performance when editing various files, I&#8217;m trying to use <code>tabpages</code> instead of only several <code>windows</code>. It&#8217;s been working as some kind of context stack for me, as there can be one <code>tabpage</code> (probably with fewer <code>windows</code>) for modifying files from a project and another <code>tabpage</code> for a different but related one (or a non-related task in the same project). Plus, using more <code>tabpages</code> and less <code>windows</code> can save precious screen space.</p>

<p>But what to do about that odious <code>tabline</code> which, besides hurting my sense of aesthetics, eats a whole line of the screen? Thankfully to the Vim&#8217;s extremely flexible nature, it didn&#8217;t take long to find an answer. It came in form of disabling the <code>tabline</code> entirely and putting its only usable information into the <code>statusline</code>. Used a bit of scripting to overcome the only corner case I could think of and took the chance to try my rusty skills on python + vim bindings. Pretty much everything someone will need to put both domains together is in this little example (besides the vim module complete <span class="caps">API, </span>easily accessible by issuing <code>:h python</code>).</p>

<p><pre><code>function! MyTabMarker(disable)
python &lt;&lt; EOF
import vim
def tabpagecount():
        return int(vim.eval(&quot;tabpagenr('$')&quot;))
def tabpage():
        return int(vim.eval(&quot;tabpagenr()&quot;))
def tabmark():
        disable = int(vim.eval(&quot;a:disable&quot;))
        if tabpagecount() &gt; 1 and not disable:
                return &quot;\&quot;[tab %d/%d] \&quot;&quot; % (tabpage(), tabpagecount())
        return &quot;\&quot;\&quot;&quot;
vim.command(&quot;return &quot; + tabmark())
EOF
endfunction

set laststatus=2
set showtabline=0
set statusline=#%02n\ %{MyTabMarker(0)}%f\ %m%r%y%=\(%bd,%Bh)\ %c,%l/%L\ %P</code></pre></p>

<p>There you see how to pass arguments into python methods and how to feed values back from it to the vim environment. Eventually I&#8217;ll publish my entire .vimrc with comments so everyone can rant about how theirs way is better <img src='http://blog.msoares.pro.br/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>[1] as I&#8217;ve lost my notebook due to a robbery at the technical assistance, my review annotations were lost too. I&#8217;ll need to re-review the book to get something published about it then.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.msoares.pro.br/archives/hiding-that-horrible-tabline-in-vim/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vim Scripting Using Python</title>
		<link>http://blog.msoares.pro.br/archives/vim-scripting-using-python</link>
		<comments>http://blog.msoares.pro.br/archives/vim-scripting-using-python#comments</comments>
		<pubDate>Fri, 10 Apr 2009 01:15:12 +0000</pubDate>
		<dc:creator>milton</dc:creator>
				<category><![CDATA[Planet INdT]]></category>
		<category><![CDATA[devel]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://msoares.dreamhosters.com/?p=39</guid>
		<description><![CDATA[Trying to solve a colleague&#8217;s problem when editing Edje files, I pushed myself into learning how to do scripting inside Vim. Scripting wasn&#8217;t ever my choice for reasonably complex editing tasks since I refused to learn Yet Another Scripting Language just because my favorite editor wanted me to. But, for the sake of all lazy [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to solve a colleague&#8217;s problem when editing Edje files, I pushed myself into learning how to do scripting inside Vim.</p>

<p>Scripting wasn&#8217;t ever my choice for reasonably complex editing tasks since I refused to learn <em>Yet Another Scripting Language</em> just because my favorite editor wanted me to. But, for the sake of all lazy guys like me, Vim started to add python support, and python was a <strong>must learn</strong> bullet in my language listing.</p>

<p>However, not everything are flowers and the entry point must be configured using common vim script. Well, at least until vim supports python from its core, which &#8211; I believe &#8211; is not far from possible, since python integration <a href="http://www.vim.org/sponsor/vote_results.php">has been voted</a> as top priority for a long time.</p>

<p>To successfully import your python script inside vim context, one can wrap it into a vim function in an external file. Let&#8217;s call it <code>extras.vim</code>.</p>

<p><pre><code>&quot; Title-ize sentences using python str methods
function! PyMakeTitle() &quot; the ! erases previous definitions
python &amp;lt;&amp;lt; END &quot; here-document (bash-style), read 'till given word
import vim
w = vim.current.window
b = vim.current.buffer
line, col = w.cursor
line -= 1
b[line] = b[line].title() # str.title() method
END
endfunction</code></pre></p>

<p>After using <code>:source extras.vim</code> command to load it, one can call this function by typing <code>:call PyMakeTitle()</code>. Remember repeating the <code>:source</code> step every time the script gets updated.</p>

<p>The net effect of this function is to turn all initial word letters in the current line into capitals. It proved me to be useful when editing a large LaTeX document where all section titles were small letters only.</p>

<p>If it comes to be a very useful function, you may map it to a key-stroke by using <code>:nmap \t :call PyMakeTitle()&amp;lt;CR&amp;gt;</code> inside your vimrc script.</p>

<p>A more complex example accessing internal vim properties. Ok, it&#8217;s a bit useless, but it demonstrates well such features.</p>

<p><pre><code>&quot; Auto Documentation (example code)
function! PyCreateDoc()
python &amp;lt;&amp;lt; END
import vim
name = vim.eval(&quot;expand(\&quot;&amp;lt;cword&amp;gt;\&quot;)&quot;) # expand word under cursor
ts = int(vim.eval(&quot;&amp;amp;ts&quot;)) # tab space property
il = int(vim.eval(&quot;indent(\&quot;.\&quot;)&quot;)) # indentation on current line
w = vim.current.window
l, c = w.cursor
docstr = '%s# @brief %s - write description' % (' ' * il, name)
b = vim.current.buffer
b[l-1:l-1] = [ docstr ]
print 'Indent set is %d, cursor at (%d, %d)' % (ts, l, c)
END
endfunction</code></pre></p>

<p>With the cursor over a function name, type <code>:call PyCreateDoc()</code> and watch it insert a line above containing doxygen-like formatting.</p>

<p>For more examples, there is an excellent material at vim&#8217;s online help (see <code>:h python</code>). Furthermore, there are some plugins being made using only python, take a look at <strong>Omni Completion for Python</strong> (<a href="http://www.vim.org/scripts/script.php?script_id=1542">pythoncomplete.vim</a>) for a good reference on the power of using python inside vim.</p>

<p>Happy Easter Vim&#8217;ing!</p>]]></content:encoded>
			<wfw:commentRss>http://blog.msoares.pro.br/archives/vim-scripting-using-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

