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:
- fill the end of the line with a two-character pattern (
£§
, chars that are unlikely to appear in your code) repeated 80 times (that is, 160 chars)
- remove everything on the line over 80 chars
- remove half of the pattern (
§
are removed and £
remain)
- copy remaining pattern to the begining of line
- replace pattern with whatever is convenient
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 @ ...