Tuesday, June 15, 2010

Re: How to center text in a comment box

On 14/06/10 12:42, Robbo wrote:
> Hello,
> if I select a text area via visual mode, how to draw a 80 chars width
> comment box and center the selected text in it?
>
> For example:
> If I select the following text:
>
> GODMORING
> GUYS
>
> I obtain
>
> /
> *******************************************************************************
> *
> GOODMORING *
> *
> GUYS *
>
> ******************************************************************************/
>
> Thank you
>
>
>

(untested). This assumes that your Vim executable was compiled with
+ex_extra and +visualextra

1. Type the interior of the box without the frame.

2. Center the text in 80 characters: select the text linewise (using V
then cursor movement), then

:'<,'>center 80

The '<,'> range is insterted automatically and means "from the first to
the last of the selected lines".

3. Add the opening comment line:

:'<-1put ='/' . repeat('*', 79)

There is just '<, not '>, and you type it yourself.

4. Add the closing comment line:

:'>put =repeat('*', 79) . '/'

No -1 this time (and no +1 either).

5. Add the asterisks at left

5a. Hit Ctrl-V in column 1 of the first line of centered text.
5b. Move the cursor down (in Block-Visual) to the last line of centered
text.
5c. hit I then * then Esc

6. Add the asterisks at right

6a. :set virtualedit=all
6b. Move the cursor to column 79 of the first centered line
('virtualedit' was used to allow moving the cursor past the end of the line)
6c. Hit Ctrl-V then move down to the last centered line while remaining
in column 79
6d. Hit A then * then Esc

6d is the most "untested" part. I think that it should put the asterisks
where you want them. If it doesn't, adding a block of blanks with
block-visual I (see 5c above, and ":help v_b_I") ought to move them to
the desired column.

7. Now you may
:set ve=
if you don't want to go on using virtual editing.


Best regards,
Tony.
--
FATHER: You only killed the bride's father - that's all -
LAUNCELOT: Oh dear, I didn't really mean to...
FATHER: Didn't mean to? You put your sword right through his head!
LAUNCELOT: Gosh - Is he all right?
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: