On Mon, Oct 12, 2009 at 4:22 PM, Jeri Raye <[email protected]> wrote:
> > Hi, > > I want to check several new-articles on the occurences of words > Therefore the two questions: > > 1) How to let vim place a carriage return after each word in an > news-article? > > And 2) If you have a text like this > > AAA > AAA > AAA > BBB > CCC > CCC > CCC > CCC > > can you let vim count the occurences of these words and add a number > before them and delete all but the first one? > So that the text above becomes: > > 3 AAA > 1 BBB > 4 CCC > > Rgds, > Jeri > > > > assuming the occurences are sequential (and that you have standard GNU tools available), you can pipe through an external process by doing ggVG to select all the text, then with the text selected, type !uniq -c<CR> this will send the text through the "uniq" command, which prints out one line for each repeated block of text. with the -c option, it will also print the number of lines in the original block. if the text is not sorted, uniq will not group together separate blocks, so if your text looked like AAA AAA AAA BBB BBB AAA AAA you would end up with 3 AAA 2 BBB 2 AAA (which may well be what you're after). if not, then you can filter through sort first by replacing the above filter command with the following (again, after having selected all the text in the buffer): !sort | uniq -c As far as doing this inside vim without using any external programs, I don't know for sure. Could probably be done with some clever macros or a custom function. -- Christopher Suter www.grooveshark.com --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
