copy paste finder : utility for viewing copied-pasted code side-by-side
| script karma
Downloaded by 1106
Comments, bugs, improvements
script versions (upload new version)
|Copy/Paste Finder (CPF) makes PMD/CPD's or Sloppy's output easier to navigate.
CPF shows detected copied/pasted regions in vertical splits and highlights
the found regions.
Homepage for development:
CPF depends on PMD or Sloppy software and needs Vim's quickfix feature.
PMD's Copy/Paste Detector (CPD) finds duplicated code.
PMD is an extensible cross-language static code analyzer.
PMD is an open source project.
see https://pmd.github.io/ to download it and for more info.
Sloppy scans all source code in a directory and generates a report on how
'sloppy' the code is... sloppiness being a measurement of a repetitive code
style: under abstraction (copy / pasting) and over abstraction (pointless
Sloppy is written by Wouter van Oortmerssen.
see http://strlen.com/sloppy/ to download it and for more info.
Tested with Vim version 8.0 on Microsoft Windows; it may work with older vim,
but not fully verified.
see the doc/cpf.txt for usage and installation instructions.
Steps below targets Microsoft Windows. Similar steps can be used with
Linux or Unix* operating systems.
- ensure java environment or sloppy executable in path
- Run gvim to open a new gvim window
- Ensure current working directory is correct in gvim
- During an editing session:
:set makeprg=cpd.bat\ --minimum-tokens\ 20\ --language\ cpp\ --files\ .
can be used with sloppy.
The command CpfNext can be repeated to see more duplicates
With Vim 8.0, if ':make!' is called then script automatically reloads the
With Vim 7.4, automatic reloading of quickfix list is not possible after
':make!' is called. The workaround is to call the command below to reload:
- can only see two windows with a (vertical) split at a time
- work along with other plugins (e.g. taglist, nerdtree...)
- support more windows; now only 2 (see wincount)
- support showing previous duplicate (opposite of Cpf_Next())
- silent, normal or execute may be redundant in some cases
- need to skip lines with no code or lines with comment only
- deciding whether to save buffers before jumping to next section
- if quickfix windows is visible may need to scroll/redraw
- may need to check and add ':noautocmd' to wincmd
| * copy pmdcpd.vim to the compiler directory
* copy sloppy.vim to the compiler directory
* copy cpf.vim to plugin directory
i.e. inside $HOME/vimfiles (or runtime directory):
* ensure java environment or sloppy executable in path
* ensure cpd (e.g. cpd.bat) is found in the path
* ensure cpd or sloppy runs correctly
The Sloppy release has sloppy.exe which runs on windows.
However for the original sloppy, a batch file is required.
For example: sloppy.bat
echo. | sloppy %*
Above batch file helps sloppy to exit---otherwise it waits for
enter key to be pressed.
Click on the package to download.
ip used for rating: 188.8.131.52