Archive for the ‘Vim’ Category

Mutt is my mail client of choice. The reasons are simple: It…

  • is fast
  • is usable from the command line (a big plus)
  • lets you do essentially anything to a message
  • supports hooks for very flexible configuraiton

And the tip of the day — how to fix unreadable (as in — mojibake mail) to be readable again.

  1. Highlight the mail in the index and press “e”. This will fire up your editor (vim in my case) and load the full mail in it.
  2. Find the “Content-Type” header. Edit the value of the “charset” field on the line. If there is no such header just add one:
    Content-Type: text/plain; charset="iso-2022-jp"

If the subject of the mail is also unreadable, do the following:

  1. Install maildrop
  2. Select the Subject line and pass it to this command cat | xargs -ifoo reformime -h "foo" | iconv -f iso-2022-jp -t utf8 | xargs -ibar reformime -o "bar" -c utf8. In vim speak, this means
    1. /^\csubject:
    2. Shift-V!cat | xargs -ifoo …
  3. Play around with the charsets if you’re not getting correct results.

Wrapping Japanese (well, any language in the CJK group) text in Vim can be tricky as there is seldom any whitespace where a line break can be inserted.

A relatively decent solution is to use this script (currently dead). It will insert a line break where necessary while avoiding inserting a break in front of punctuation or other special symbols.

Another quicker solution is to set the “m” and “B” format options: :set fo+=mB
m will make it possible to break between any multi-byte characters, and B will prevent the insertion of space between multi-byte characters when joining lines with “gj” for example. This will quickly do the job, but with no regard for punctuation.

Keep in mind that with both methods Cyrillic characters are treated as ordinary multi-byte characters. Therefore, it is not a good idea to have these settings automated if you are going to be handling Bulgarian for example. Considering the previous statement, it is easier to turn on/off the format-options compared to loading/unloading a script.

Inserting page breaks when printing in VIM is trivial but I had never had to do it. It basically involves two steps.

First, insert the form-feed character in your file where you want a page break to occur. The character is 0×0C and you can use Control+V and then Control+L to insert it. It will display as “^L” on the screen.

Second, tell VIM to obey these breaks by adding formfeed:y to your printoptions. In other words
:set printoptions=formfeed:y

And now print. It should work with no problem at all.

In Vim, to move the cursor to a location where there is no character, use the “virtualedit” or “ve” commands. E.g., :set ve=all and then move around freely. I always keep forgetting that.