On Mon, 26 Feb 2007 16:30:09 -0800, Lev Lvovsky <[EMAIL PROTECTED]>
wrote:

> I'm sure there's a fancy word for this, but is there any way to pull  
> text to the right?
> 
> suppose I have the following:
> 
>       COL1  INT,
>       COL2  INT,
>   COL3           INT,
> 
> I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,  
> I need to put the cursor behind "COL3", hit space several times, and  
> then align "INT" with the other "INTs".  Can I put my cursor to the  
> right of "COL3", and pull it over to "INT" on the right?

I wouldn't bother with anything more than basic editing commands for
a single change like this. Just press I (to start inserting to the
left of the COL3), type spaces until the column is aligned, then Esc
kwwj (to put you in the right place for the INT) and dw (to remove the
unwanted spaces).

If you have tabs in the middle of the lines you may also need to press
i and some more spaces because the dw may remove too much.

Alternatively, this crude mapping will pull things over towards the
cursor. It works by transferring one whitespace character from one
side of the COL3 to the other:

:map [whatever] 
:s/^\\(\\s*\\)\\(\\S.\\{-}\\)\\(\\s\\)\\(\\s*\\)\\%#/\\1\\3\\2\\4/<CR>``

Debackslashed, that expression is:

s/^\(\s*\)\(\S.\{-}\)\(\s\)\(\s*\)\%#/\1\3\2\4/

That is, match the leading spaces (if any), one or more words,
a single space, and then any additional spaces up to the cursor
position, and replace them but moving the single space to just
before the words.

-- 
Matthew Winn

Reply via email to