Vim plugin to highlight source code lines that lack test coverage.
Currently supports only these Python coverage tracking tools:
- coverage.py
- trace.py (obsolete)
- Generate some coverage data (a
.coveragefile) by running your tests withcoverage run(or by using the appropriate test runner plugin). - Open a source file in vim
:HighlightCoverage
- :HighlightCoverage
Highlight untested source code lines.
Tries to find the corresponding coverage report by looking for files named
.coveragehere (or in parent directories).Also looks for looking for files named
coverage/<module>.reportto supporttrace.pyreports, which are produced by zope.testrunner if you specify--coverage=coverage.- :HighlightCoverage NN-NN,NN-NN,NN,...
Highlight the specified source code lines and ranges.
The format matches that produced by
coverage report -m, so you can copy & paste the ranges to the Vim command line from a web page, instead of having to hunt down and download.coveragefiles.- :HighlightCoverage <filename>.report
Highlight untested source code lines from a trace.py report.
Report files are just source code files indented with the number of executions or '>>>>>>' for uncovered lines prepended at the left margin.
- :HighlightCoverageForAll
Highlight untested source lines for all files mentioned in the coverage report.
Only works with
coverage.pyreports.Skips files not currently loaded into buffers, due to a limitation of Vim.
- :HighlightCoverageOff
- Turns off coverage highlighting
- :ToggleCoverage
- Toggles coverage highlighting on and off
- :NextUncovered
- Jump to the next uncovered range of source lines
- :PrevUncovered
- Jump to the previous uncovered range of source lines
- g:coverage_script
Default: "" (which means autodetect)
Name of the script that can produce reports. Example:
let g:coverage_script = 'python3 -m coverage'
By default it looks for
coveragein your PATH, and if not found, it looks forbin/coveragerelative to the current working directory.- g:coverage_script_args
Default: "--no-skip-covered"
Additional arguments to be passed to coverage report.
- g:coverage_sign
- Default: "↣" (">>" on non-UTF-8 setups)
- g:coverage_sign_branch
- Default: "↦" ("~>" on non-UTF-8 setups)
- g:coverage_sign_branch_target
Default: "⇥" (">~" on non-UTF-8 setups)
Signs used in sign_column (empty string allowed). Example:
let g:coverage_sign = '#' let g:coverage_sign_branch_target = ''
If you want to change the highlighting, add this to your .vimrc:
highlight NoCoverage ctermbg=... guibg=... highlight NoBranchCoverage ctermbg=... guibg=... highlight NoBranchCoverageTarget ctermbg=... guibg=...
with the colors you want. See vim's :help cterm-colors and
:help gui-colors for the color values to use.
You may want to add this to your .vimrc:
noremap [C :<C-U>PrevUncovered<CR> noremap ]C :<C-U>NextUncovered<CR>
Add %{coverage_highlight#get_current()} to your 'statusline' to show the
coverage percentage for the current file, updated when you run
:HighlightCoverage.
Add %{coverage_highlight#get_total()} to your 'statusline' to show the
coverage percentage for the current project, updated when you run
:HighlightCoverageForAll.
You can pass a format string to either function to customize how the coverage is to be displayed. The default is "%s%%".
Example
set statusline=%<%f\ %h%m%r\ %1*%{coverage_highlight#get_current()}%*%=%-14.(%l,%c%V%)\ %P
Vim 8.0.0251 or newer with Python or Python3 support.
coverage-highlight.vim was written by Marius Gedminas <[email protected]>
and contributors.
Licence: MIT.
