On 20/07/09 23:59, John Sampson wrote:
>
> Hello -
>
> I want to change lines of the form
>
> able|baker|charlie|dog|easy
>
> to
>
> baker|able|charlie|dog|easy
>
> With the cursor on the line I can do this with the command
>
> :.s/\(\[^\|\]*\)\(|\)\(\[^\|\]*\)\(|\)\(.*\)/\3\2\1\4\5/
>
> which looks like a diagram for the cutting edge of
> a tunnelling machine.
>
> In order to do this more than once I would like to be able to represent
> this with a typable
> command such as "swap12", preferably in the .vimrc file assuming that
> this initialises Vim when
> Vim is started up. Is there a way of doing this in Vim? I might have
> expected to be able to use
> 'map' or 'ab' or 'command' but these all fail. I tend to get a 'trailing
> characters' error message
> but it does not tell me which characters are trailing or what the
> objection is to having
> trailing characters. I am working in Windows XP so line-end character
> incompatibilities may
> be complicating this matter.
>
> It may be that I have over- or under-escaped some characters - is there
> a clear account
> of the subject of escaping in the Vim literature?
>
> Regards
>
> _John Sampson_
:help :command
:help map.txt
You may also simplify the substitute, e.g. (untested)
:s/^\(.\{-}\)\(\%x7C\)\(.\{-}\)\ze\%x7C/\3\2\1
Best regards,
Tony.
--
Why don't elephants eat penguins ?
Because they can't get the wrappers off ...
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---