Move my cursor

Cursor movement in most editors (ed users can stop now) is a fundamental operation. In Vim (and old vi) cursor movement commands can be used in combination with other commands.

Most users know that dd deletes a line, but many do not know that it is actually a simplified form of the d command that deletes whatever you define with a cursor movement operation. I’ll explain with examples:

  • l (and the right-arrow key) moves one character right, so dl deletes the character under the cursor (since the cursor position is actually the left hand edge of the visible cursor), but x also deletes to same character, so use that instead;
  • w moves to the start of the next word, so dw deletes to the start of the next word;
  • ^ moves to the start of the line, so d^ deletes to the start of the line;
  • $ moves to the end of the line, so d$ deletes to the end of the line, but D also deletes to the end of the line, so use that instead;
  • G moves to the end of the file, so dG deletes to the end of the file;
  • { and } move back and forward paragraphs, so d{ deletes a paragraph backwards and d} deletes a paragraph forwards;
  • t moves forward (within a line) until it finds a character you specify, so tp will move forward until it finds a p (it won’t move if there is no p), so dtp will delete up to the p;
  • ' moves to the start of the line containing the mark you specify (you do know how to make marks, don’t you?) and ` moves to the actual mark position, so d'a will delete to the start of the line you marked with a and d`o will delete to the o mark;

There are too many other cursor movement commands for me to show, and there are many other commands that can use them. Of these, my next 2 favourites are y and =. y is the copy equivalent to the cut of d, and I’m assuming you know that p is paste. = is the smart indent command.

Published
Categorized as Uncategorized Tagged

Make your mark

Making marks in Vim (and old vi) allow you to find particular places in your file without having to scroll or remember line numbers: just remember a letter. For example, typing ma will mark your current position with the a mark; you won’t see anything, but Vim will remember. Now move somewhere else in your file and type mb to mark it as b (or replace b with your favourite letter).

Once you have marked positions, you can jump to them: 'a will jump to the start of the line you marked with a and `b will jump to the exact position you marked with b.

Published
Categorized as Uncategorized Tagged

Debian install from PXE

Our new server has PXE support to boot from scratch from the network, so I decided to try to install Debian with it. I didn’t just do this for fun (it wasn’t much fun): the new server had a gigabit ethernet card that wasn’t supported by my usual Debian network boot CD.

I started with syslinux, as it includes pxelinux and lots of helpful documentation. I choose atftpd for my TFTP server since its author (Jean-Pierre Lefebvre) wrote it to use with pxelinux.

I wanted to use udhcpd as the DHCP server because I liked udhcpc, but the client machine didn’t seem to like it: it seems that PXE might use some non-standard DHCP features. So, I used ISC dhcpd3, and it worked. But that was another surprise: it worked even though the DHCP port was being filtered by the local firewall! I assume this is becuase dhcpd3 uses the packet protocol to bypass the normal protocol stack. That’s also why it requires packet socket and socket filtering to be compiled into the kernel. I don’t like it, but it works.

Published
Categorized as Uncategorized Tagged

Posting to my Blog

I don’t post to this blog as frequently as I would like. There are many reasons why, but there is now 1 less than before.

I didn’t like editing in the browser, and I didn’t want to edit offline and then cut’n’paste. What I wanted was to be able to edit offline and then simply upload the finished file whenever I next connected. So, I wrote a short Perl script to do that for me, and this entry is my test case.

Learning Japanese

I started a Japanese language course at the EIC Japanese Language Center. I only have 3 weeks left in London, and 2 evenings per week available for lessons. Normal lessons would not suit because my existing knowledge of Japanese is weird: I understand some advanced grammar but my vocabulary is miniscule. The staff at EIC handled my requirements very well, and I really like my new set of flash cards.

Origami with Vim

Imagine you have a sheet of A4 paper with some of your code printed on it. (You need a good imagination; maybe you should go and print some code now…) Now find the start of a block, any block. Carefully make a mountain fold just below the first line of you chosen block, then make a valley fold in the middle of your block. Now look at your code.

You chosen block has vanished, apart from the first line, but the rest of your code is still visible. Now, assuming you know what the missing block does, your code is easier to read because it fits on a smaller page. Wouldn’t it be great if you could fold your screen?

Vim can do this for you, without damaging any hardware.

Look at your (imaginary) sheet of paper again. Lift it up to eye level and look at its side: your fold is Z shaped; so vim uses the z character for folding commands:

  • zo opens a fold so you can see the hidden parts;
  • zc closes a fold, hiding its contents;
  • zf creates a fold that you mark with a cursor movement;

For all the details, see :help folding in Vim.

If you’re using Perl and you want Vim to automatically make folds for your blocks and POD, add the following to your .vimrc:

  let perl_fold = 1
  let perl_fold_blocks = 1
Published
Categorized as Uncategorized Tagged