rotation

2007-03-07 Thread fREW

Does anyone know if there are any builtin commands to rotate the
current line about a character or word?

Example:
rotate about the j and just respectively
'This is just a test ' becomes 'ust a testj This is'
'This is just a test' becomes 'a test just This is'

I know it would be pretty easy to do these with macros, but I thought
there might be some builtin or something.

Thanks!

--
-fREW


Re: rotation

2007-03-07 Thread A.J.Mechelynck

fREW wrote:

Does anyone know if there are any builtin commands to rotate the
current line about a character or word?

Example:
rotate about the j and just respectively
'This is just a test ' becomes 'ust a testj This is'
'This is just a test' becomes 'a test just This is'

I know it would be pretty easy to do these with macros, but I thought
there might be some builtin or something.

Thanks!



1) :s/\(^.*\)\(j\)\(.*$\)/\3\2\1
actually it will give ust a testjThis is .

2) :s/\(^.*\)\( just \)\(.*$\)/\3\2\1

see
:help /\(

(Note: Without a range, :s defaults to the current line.)


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
96. On Super Bowl Sunday, you followed the score by going to the
Yahoo main page instead of turning on the TV.


Re: rotation

2007-03-07 Thread Tim Chase
 Does anyone know if there are any builtin commands to rotate
 the current line about a character or word?
 
 I know it would be pretty easy to do these with macros, but I
 thought there might be some builtin or something.

There's nothing built-in, but you can map something of the like:

 rotate about the j and just respectively
 'This is just a test ' becomes 'ust a testj This is'

According to your description of what rotating should do,
rotating around the j in this example would yield

'ust a test jThis is '

rather than

'ust a testj This is'

but can be done with

:nnoremap gw :s/^\(.*\)\%#\(.\)\(.*\)$/\3[\2]\1cr

 'This is just a test' becomes 'a test just This is'

This can be done with:

:nnoremap gW :s/^\(.\{-}\)\(\s*\\w*\%#\w*\s*\)\(.*\)$/\3\2\1cr

Though somewhat funky things happen if you're in whitespace
rather than over Word characters.

I don't recall if the \%# was added in Vim7 or if it works in
prior versions.  YMMV.

HTH,

-tim








Re: rotation

2007-03-07 Thread fREW

Cool!  Thanks Tim and A.J.

And yeah, sorry about the typo with  'ust a test jThis is ', I meant
to include that space.
And I use Vim7 so I can use any extensions that may have been added then.

Thanks again!

-fREW

On 3/7/07, Tim Chase [EMAIL PROTECTED] wrote:

 Does anyone know if there are any builtin commands to rotate
 the current line about a character or word?

 I know it would be pretty easy to do these with macros, but I
 thought there might be some builtin or something.

There's nothing built-in, but you can map something of the like:

 rotate about the j and just respectively
 'This is just a test ' becomes 'ust a testj This is'

According to your description of what rotating should do,
rotating around the j in this example would yield

'ust a test jThis is '

rather than

'ust a testj This is'

but can be done with

:nnoremap gw :s/^\(.*\)\%#\(.\)\(.*\)$/\3[\2]\1cr

 'This is just a test' becomes 'a test just This is'

This can be done with:

:nnoremap gW :s/^\(.\{-}\)\(\s*\\w*\%#\w*\s*\)\(.*\)$/\3\2\1cr

Though somewhat funky things happen if you're in whitespace
rather than over Word characters.

I don't recall if the \%# was added in Vim7 or if it works in
prior versions.  YMMV.

HTH,

-tim