On Thu, 4 Feb 2010, drlatex wrote:

> 
> Hello,
> 
> Is it possible for vim to search for repeated strings in a document ?
> 
> For example, the file:
> 
> abc
> def
> 123
> 654
> bcd
> 
> has no repeated strings,
> 
> But the file:
> 
> 1234
> 2345
> 1567
> 1234
> 3214
> 
> has the redundancy on lines 1 and 4.
> 
> This might be hard because in the first file, the string 'bc' is in 
> fact repeated on lines 1 and 6, but I am looking for if the file has 
> two lines that are redundant.
> 
> Any help, suggestions or discussion is greatly appreciated,
> 

Wow... Vim is getting fun...

Add the following to a file called ~/.vim/compiler/dups.vim:

CompilerSet makeprg=sort\ %\\\|uniq\ -d\\\|grep\ -Hnxf\ -\ %
CompilerSet errorformat=%f:%l:%m

and you can then call:

:compiler dups

in a buffer.  Then when you ':make', you can get a list of errors by 
running ':cope'.

I'm still a 'quickfix' noob, so this may not be the way to go about it.  
I don't know (for example) how to deal with an existing other 
compiler...

The 'makeprg' line does the following:

The '\' are for escaping for Vim's purposes.

Unescaped and nicer, the command is:

sort % | uniq -d | grep -Hnxf - %
     |        |          |||| |
     |        |          |||| \-- the duplicates from stdin
     |        |          |||\-- file with patterns to match
     |        |          ||\-- matches are whole-line only
     |        |          |\-- print line number
     |        |          \-- print filename
     |        \-- prints out any duplicated lines
     \-- the current buffer

You can also simply run that command on the current buffer:

:!sort %|uniq -d|grep -Hnxf - %

-- 
Best,
Ben

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to