Gary Johnson wrote:
You could first sort the file,

    :%sort

then search for duplicate lines in the result,

    /\(^.*\)\n\1

If sorting the file is allowed, I'd use Gary's solution with one small tweak:

  /^\(.*\)\n\1$

(adding the "$") to prevent these sorts of matches from being found

  1234
  12345

If you don't want to sort the file, you could use something like

 /^\(.*\)\ze\_$\_.\{-}\_^\1$

which would find/highlight anything that has a following match (which means the final match wouldn't be hit). It may be a bit slow with a larger file because of the distance it may have to search for each line, but it should be a good way to find hits without sorting your file.

If you want to have them all in a data-structure, you can use Brett's suggestion


:let dict = {}|let arr = []|g/^./exe "if has_key(dict, getline('.'))|
call add(arr, line('.'))|endif|let dict[getline('.')] = 1"

though I don't think the "exe" is needed, making it

:let d={}|let a=[]|g/^./if has_key(d, getline('.'))|call add(a, line('.'))| endif | let d[getline('.')] = 1

You can adjust what gets stashed in "a" instead of line('.') if you want the duplicates' content instead of line#.

-tim






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

Reply via email to