Saturday, January 25

I've been reading some of the Vim help files lately. They're imperfect — you don't always know what exists, and the English can be a little rough around the edges — but there's a lot of text, and it is full of potentially useful stuff.

I've been getting interested in Vim's built-in scripting language. Most of the commentary I've read indicates that it's sort of weird and clunky. As near as I can tell, it is definitely weird, but it's also surprisingly featureful, in a somewhat ad hoc way. For example, one of its built-in types is a dictionary, more or less corresponding to a Perl-style hash (but with optional dict.whatever notation for accessing elements), and another is a function reference. If you want to stuff function references into dictionaries, you can get syntactic sugar whereby functions can use self to refer to the containing dictionary. You can even do this with anonymous functions. Presto, instant objects. Kind of, at least.

Less surprisingly, Vim also has a more sophisticated model of variable scope than languages I frequently use it to write, such as PHP. Here's a table, adapted a bit from the text of :help vim-script-intro:

There are several name spaces for variables. Which one is to be used is specified by what is prepended:

(nothing) In a function: local to a function; otherwise: global
b: Local to the current buffer.
w: Local to the current window.
t: Local to the current tab page.
g: Global.
l: Local to a function.
s: Local to a :source'ed Vim script.
a: Function argument (only inside a function).
v: Global, predefined by Vim.
 
& Option, local if possible.
&g: Global option.
&l: Local option.
$ Environment variable.
@ Register.

Well, at least it's explicit and granular. You can also do the equivalent of array slices, map(), and various kinds of regex matching. The devil, as always, is in the details, and I need to play with this, but I start to suspect that it's more capable than scripting environments I've used heavily in the past.

Anyway. There's an important takeaway here: It's 11:56 on Saturday night, and I'm sitting at home in my bathrobe drinking 90 Shilling and going over the documentation for a text editor.

Easy, ladies. There's plenty to go around.