Is there a way to easily create a text header in VI? I would like to create a header such as the one below without having to count characters for the purpose of centering.
# ********** a centered title **********
Any vi voodoo to be had? A better method?
You can center the current line by using :center (in vim). Then use 'R' to fill in the asterisks after the fact. Still not fast or magical, but at least it saves you from counting characters.
So the steps would be:
Upon further testing, you need to have "set expandtab" turned on, otherwise centering will use tabstops and you end up replacing them with single characters which undoes the centering.
Here is a macro to add in .exrc file for old vi:
map £ A ^[80A£§^[080lD:s/§//g^M$byw0Pa ^[080lD:s/£/*/g^M0R# ^[^M
(Typing ^[ is obtained with the sequence CTRL-V followed by ESC. Typing ^M is obtained with the sequence CTRL-V followed by ENTER)
The idea is to:
£§, chars that are unlikely to appear in your code) repeated 80 times (that is, 160 chars)§ are removed and £ remain)To use the macro, put the cursor on the line to be centered and just type £. You can choose any character, e.g., @ by changing the macro name: map @ ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With