bairui

Unique Lines in Vim

Jan 9th, 2012
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.43 KB | None | 0 0
  1. " Unique Lines
  2. " Barry Arthur, 2012 01 09
  3.  
  4. let b:unique_lines = []
  5. function! Unique(line)
  6.   let l = getline(a:line)
  7.   1
  8.   let n = search(l, 'w')
  9.   if n != a:line
  10.     return
  11.   endif
  12.   let n = search(l, 'W')
  13.   if n == 0
  14.     call add(b:unique_lines, a:line)
  15.   endif
  16. endfunction
  17.  
  18. 22,$g/./call Unique(line('.'))
  19. echo "Unique Lines = " . string(b:unique_lines)
  20. nohl
  21.  
  22. finish
  23.  
  24. one
  25. one
  26. two
  27. three
  28. three
  29. dour
  30. four
  31. dour
Advertisement
Add Comment
Please, Sign In to add comment