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 “firstname.lastname@example.org” as soon as you typed “mlLong” in insert mode, just insert the following in your ~/.vimrc file:
:iab mlLong email@example.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 “firstname.lastname@example.org”.
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).