On Sun, Jul 5, 2009 at 7:15 AM, Jeri Raye <[email protected]> wrote:
> > Hi, > > If a line contains a , this , should have only one space character and > also only one space character > after it. How do you do that? > > So the following: > sX,sY > sX ,sY > sX, sY > sX , sY > > Must all be come (the last one should be trimmed to one space before > and after the ,) > sX , sY > This is trickier than it at first appears. Pattern matching is greedy by default, matching as many characters as possible. So normal wildcard matching could end up including commas when that's not what you want. (If there is more than one comma on a line it will probably skip all but the last.) There may be a more clever way to do it using some of the rather specialized wildcard sequences in a single substitution. The straightforward way is to do it in two passes. First be sure all the commas have spaces around them by doing this: :%s/,/ , /g Then get rid of the excess spaces around the commas with: %s/\s\+,\s\+/ , /g That did the trick on a trial using your sample input. I'm pretty sure it should also work in more complicated situations. -- Jay --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
