Thursday, May 21, 2009

Vim Statusline

To start off my reinvigorated vim education, I looked into why I get a helpful info bar when I have :split windows, but not when I am looking at a single file. The bar is called the statusline (:help status-line), and you can change the visibility option with
set laststatus=<#>
It defaults (on my system) to 1, meaning that it only shows for split windows. To make it always show, set it to 2.


The helpdoc informs us that you can set the content of the statusline with:
set statusline=[some string]
[some string] is a printf-style string, with a host of items it can display (:help statusline). I liked the default (with the rails.vim addition of rails filetype information), but I wanted to also see the buffer number, because I've been playing around with buffer management. Here's what I ended up with, in my .vimrc:
set statusline=
set statusline+=%<\ " cut at start
set statusline+=%2*[%n%H%M%R%W]%*\ " buffer number, and flags
set statusline+=%-40f\ " relative path
set statusline+=%= " seperate between right- and left-aligned
set statusline+=%1*%y%*%*\ " file type
set statusline+=%10((%l/%L)%)\ " line and column
set statusline+=%P " percentage of file

Which gives a statusline like:
[10] app/models/user.rb          [ruby][Rails-model-arb]    (1/276) Top

Vim

I use vim daily for my routine development work, and I get along fine with it. When I first got into it, I scrambled up the steep learning curve until I got to a plateau where I could be productive, and haven't given it much thought since then. I can do all the basic stuff (and a few cool tricks), but other than that my editor is pretty low on the list of things I want to devote thought to.

My position changed, however, when a coworker recently decided to jump on the vim bandwagon. His daily excitement over some newly discovered command or plugin was just what I needed to reignite my interest, and I've started to climb the slopes again.

I'll share what I discover here. Most of it will probably fall in what I'd consider the intermediate level, but undoubtedly there will be some more basic stuff that I'd never come across (or taken the time to delve into). Part of my problem is that when I was originally learning vim I didn't rely on the help system (which is extensive), but instead played around with things until I was comfortable with them -- so I'll be focusing on :help a lot more this time around, to fill in the gaps. Hopefully my progress will be of some help to other vimers that have been skating by for too long.

Tuesday, May 12, 2009

Firebug's Console Pitfall

Beware -- if you leave a reference to the 'console' object in your javascript and deploy it out, your site will not behave!

I absentmindedly deployed code with a 'console.debug()' in the javascript, and a quick test showed the site to be functioning. When I tried again in the morning (from my work computer), a dropdown was unpopulated. I enabled firebug for the site to check things out, but when the page reloaded things were fixed.

Whenever it was that I learned about the console object, I just took it for granted, and didn't bother to look up anything about it. So, not only did I not realize that it's provided by firebug (and only available when console is enabled for the site), but I also have been missing out on a variety of other cool methods off of console, such as dir(), trace(), and profile(): API