Block Editing in Vim

I have been lax in adding to this site for some time, but I am hoping to rectify that in the coming weeks. Luckily I have a backlog of things that I have done that will make up the next few entries. For instance, I have come to love Visual Block editing in vim.

When I’m debugging code it is just magic to be able to comment out a block at a time to test various aspects of a program. For a long time now I’ve been referring to a copy-and-pasted section of the vim manual in a loose file, because I don’t use the features so often that it sticks in my mind yet. To avoid collecting these loose files, I’ll put the relevant section here, so I can find it.

Visual-block Insert *v_b_I* With a blockwise selection, I{string} will insert {string} at the start of block in every line of the block, provided that the line extends into the block. Thus lines that are short will remain unmodified. TABs are split to retain visual columns.

Visual-block Append*v_b_A* With a blockwise
selection, A{string} will append {string} to the end of block on every line of the
block. There is some differing behavior where the block RHS is not straight, due to different line lengths:

1. Block was created with $ In this case the string is appended to the end of each line. 2. Block was created with {move-around} In this case the string is appended to the end of the block on each line, and whitespace is inserted to pad to the end-of-block column.

Note: “I” and “A” behave differently for lines that don’t extend into the selected block. This was done intentionally, so that you can do it the way you want.

LaTeX

A while back I was using CVS to synchronize and version my school work, and I was looking for a method of writing papers so the working files were text instead of binary allowing diffs to be generated via CVS. That lead me to LaTeX, and it worked out all right. I found that I was quite happily able to generate my text in vim, version it with CVS and generate a final PDF, the only binary format in the whole process.

Now, well after I really could have used it, this article pops up. It is a useful primer, but it doesn’t really touch on the one things that will probably bite a lot of users in the ass – there are zillions of versions of LaTeX and its packages, and so you’ll have to experiment to find out what works on your system. Still, it’s a good document preparation system, and I’m glad to know something about how it works.

USB Keys

I had a store credit to use up before Christmas, and so I bought a couple of USB key storage devices, one for the lady and one for me. I was quite please at how easy the were to set up, just adding a line to /etc/fstab and mounting the device. For the longest time though, I could only perform operations on it as root, which is tiresome. Luckily, Emma pointed me at some good documentation and so I was able to get everything working sweetly. Here’s what I’ve got working:

# A directory called /mnt/key
# These lines in /etc/fstab
none        /proc/bus/usb usbfs defaults            0   0
/dev/sda    /mnt/key    vfat    rw,user,noauto      0   0
# And these lines in my .bashrc
alias key="mount /dev/sda;ls /mnt/key"
alias unkey="umount /mnt/key"

It works pretty sweetly, and these storage devices are awesome. I’ve never gotten close to filling it up yet.