Save typing using vi abbrevations

May 11th, 2007 Felix Leong Posted in vi, vim | Hits: 53367 | 2 Comments »

Do you find yourself typing some long text too often that it’s getting tiresome (especially when it comes to hard to remember and long email addresses)? Or that you are so bad at remembering today’s date that you have to fumble through the calendar before you are able to type away?

If you are using vi, then abbreviation is the function just for you.

So let’s say you want to vi to automatically insert “a-very-long-name@a-long-mail-address.com” as soon as you typed “mlLong” in insert mode, just insert the following in your ~/.vimrc file:

:iab mlLong a-very-long-name@a-long-mail-address.com

Then bring up your vi editor, get into Insert mode, try to type “mlLong”. As soon as you press the space/tab key, viola! “mlLong” will be auto-magically changed to “a-very-long-name@a-long-mail-address.com”.

Let say you want to use the “Ydate” abbreviation to be replaced as the current date, you can make use of vi’s expressions by adding the following into you ~/.vimrc file:

:iab Ydate <c-r>=strftime("%d-%m-%y")<cr>

This will make “Ydate” an abbreviation to the current date in “dd-mm-yy” format.

Do note that the replacement text will be copied verbatim so there’s no need to use escape sequences (i.e. use the real tab instead of “\t” in your :iab line).

[中文翻译]

2 Responses to “Save typing using vi abbrevations”

  1. [...] Save typing using vi abbrevations Do you find yourself typing some long text too often that it’s getting tiresome (especially when it comes to hard to rem… [...]

  2. [...] After all, I just enjoy greping with regex Related Posts Save typing using vi abbrevations Do you find yourself typing some long text too often that it’s getting tiresome (especially when it comes to hard to rem… [...]

Leave a Reply