Wednesday, July 29, 2009

Types of Registers

There was some mention of the special registers in Vim in the comments on my last post. Here's a list of all available registers in Vim (copied directly from the docs). For more info on what these registers do, please see :help registers.

There are nine types of registers:
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 named registers "a to "z or "A to "Z
5. four read-only registers ":, "., "% and "#
6. the expression register "=
7. The selection and drop registers "*, "+ and "~
8. The black hole register "_
9. Last search pattern register "/

Tuesday, July 28, 2009

Insert Register Contents

If you're in insert mode and would like to insert the contents of a given register without going into normal mode, you can hit ctrl-r and then input the desired register. Between typing ctrl-r and the second character, a '"' will be displayed to indicate that you are expected to enter a register.

Friday, June 19, 2009

An Introduction to Clojure's Agents

For anyone that's interested in alternative programming languages, I've written a lengthy introduction to Clojure's agents.

For those unfamiliar with Clojure, it's a modern Lisp running on the JVM with excellent support for concurrency. It allows excellent interoperability with Java, so essentially you get a dynamic and clean programming language with a huge standard library. On the performance front, it's often on par with Java. I've spent a good deal of time learning the language lately, and I have to say that it's very enjoyable to work with.

One huge bonus of working with Clojure inside Vim is the VimClojure project. It allows interactive programming from inside of Vim and proxies code between a stateful NailGun server and the editor. To be honest, I wasn't aware that an interactive REPL was possible inside of Vim until I installed this, and I'm wondering if there are any other projects out there using similar techniques with different languages.

Wednesday, June 17, 2009

Switching from Horizontal to Vertical Split

If you have two windows which are horizontally split, and you'd like to make them vertically split instead, the following command sequence works well:

<ctrl-w>t<ctrl-w>H

To orient them back to a horizontal split do this:

<ctrl-w>t<ctrl-w>K

Note that if the top (or left) window is already current you can omit the <ctrl-w>t and simply do <ctrl-w>H or <ctrl-w>K.

Monday, June 15, 2009

Vi Mode in Readline Applications

Mike Pea submitted this comment in a recent tip, and I thought it deserved it's own post.

If you find that you do like using vi editing mode (and what's not to love about it :), add 'set editing-mode vi' to your .inputrc, and vi mode will work in any readline based client, eg psql, irb.

Thanks Mike!

Friday, June 12, 2009

Recursive Macros

A friend at work pointed out to me yesterday that he had accidentally written a recursive macro in Vim. I had never thought about the fact that this was possible, but I'd imagine there could be some potential usefulness for these somewhere. As a trivial (and useless) example, here's a recursive macro to move the cursor to the end of the current line one step at a time: qal@aq

Edit: A little research has shown that this is an excellent way to repeat a macro to the end of the file. Say that you have a file containing one number per line from top to bottom:

123
234
345
456

Put the cursor on the first line and type the following:

qaq (clears register "a" of any previous macros)
qa<ctrl-a><enter>@aq

Now type @a once more, and the macro will run to the bottom of the file incrementing the value on each line by one leaving you with the following:

124
235
346
457

Friday, June 5, 2009

Screen in OS X Leopard

Sorry for the horribly platform specific tip, but this has been annoying me, and I thought it might help someone. If you're running OS X 10.5, you may have noticed that screen destroys your path when you start it. This can easily be remedied by putting the following in your ~/.screenrc.

shell -/bin/bash