copy paste finder : utility for viewing copied-pasted code side-by-side
script karma |
Rating 4/8,
Downloaded by 1166 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
skycolor radialsum |
|
script type |
utility |
|
description |
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:
https://github.com/Radialsum/copy-paste-finder
Screenshot:
https://github.com/Radialsum/copy-paste-finder/blob/master/cpf-v002.png
CPF depends on PMD or Sloppy software and needs Vim's quickfix feature.
PMD/CPD:
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:
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
complexity).
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.
Usage:
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:
:compiler pmdcpd
:set makeprg=cpd.bat\ --minimum-tokens\ 20\ --language\ cpp\ --files\ .
:make!
:CpfNext
Or
:compiler sloppy
:makeprg=sloppy.bat
:make!
:CpfNext
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
quickfix list.
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:
:call Cpf_LoadQflist()
Limitations:
- 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
|
|
install details |
* 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):
compiler/pmdcpd.vim
compiler/sloppy.vim
plugin/cpf.vim
* 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 off
echo. | sloppy %*
Above batch file helps sloppy to exit---otherwise it waits for
enter key to be pressed.
|
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 3.239.76.211
|