cp.nvim/doc/cp.txt
2025-09-14 20:41:10 -05:00

242 lines
8.2 KiB
Text

*cp.txt* Competitive programming plugin for Neovim
Author: Barrett Ruth <br.barrettruth@gmail.com>
License: Same terms as Vim itself (see |license|)
INTRODUCTION *cp* *cp.nvim*
cp.nvim is a competitive programming plugin that automates problem setup,
compilation, and testing workflow for online judges.
Supported platforms: AtCoder, Codeforces, CSES
REQUIREMENTS *cp-requirements*
- Neovim 0.10.0+
- uv package manager (https://docs.astral.sh/uv/)
- C++ compiler (g++/clang++)
Optional:
- LuaSnip for template expansion (https://github.com/L3MON4D3/LuaSnip)
COMMANDS *cp-commands*
*:CP*
cp.nvim uses a single :CP command with intelligent argument parsing:
Setup Commands ~
:CP {platform} {contest_id} {problem_id}
Full setup: set platform, load contest metadata,
and set up specific problem. Scrapes test cases
and creates source file.
Example: :CP codeforces 1933 a
:CP {platform} {contest_id} Contest setup: set platform and load contest
metadata for navigation. Caches problem list.
Example: :CP atcoder abc324
:CP {platform} Platform setup: set platform only.
Example: :CP cses
:CP {problem_id} Problem switch: switch to different problem
within current contest context.
Example: :CP b (switch to problem b)
Action Commands ~
:CP run Compile and run current problem with test input.
Shows execution time and output comparison.
:CP debug Compile with debug flags and run current problem.
Includes sanitizers and debug symbols.
:CP diff Enter diff mode to compare actual vs expected
output. Run again to exit diff mode.
Navigation Commands ~
:CP next Navigate to next problem in current contest.
Stops at last problem (no wrapping).
:CP prev Navigate to previous problem in current contest.
Stops at first problem (no wrapping).
CONFIGURATION *cp-config*
cp.nvim works out of the box. No setup required.
Optional configuration with lazy.nvim: >
{
'barrett-ruth/cp.nvim',
cmd = 'CP',
opts = {
debug = false,
contests = {
default = {
cpp_version = 20,
compile_flags = { "-O2", "-DLOCAL", "-Wall", "-Wextra" },
debug_flags = { "-g3", "-fsanitize=address,undefined", "-DLOCAL" },
timeout_ms = 2000,
},
atcoder = { cpp_version = 23 },
},
hooks = {
before_run = function(problem_id) vim.cmd.w() end,
before_debug = function(problem_id) ... end,
},
tile = function(source_buf, input_buf, output_buf)
end,
filename = function(contest, problem_id, problem_letter)
end,
}
}
<
Configuration options:
contests Dictionary of contest configurations - each contest inherits from 'default'.
cpp_version c++ standard version (e.g. 20, 23)
compile_flags compiler flags for run builds
debug_flags compiler flags for debug builds
timeout_ms duration (ms) to run/debug before timeout
snippets LuaSnip snippets by contest type
hooks Functions called at specific events
before_run Called before :CP run
function(problem_id)
(default: nil, do nothing)
before_debug Called before :CP debug
function(problem_id)
(default: nil, do nothing)
debug Show info messages during operation
(default: false, silent operation)
tile Custom function to arrange windows
function(source_buf, input_buf, output_buf)
(default: nil, uses built-in layout)
filename Custom function to generate filenames
function(contest, problem_id, problem_letter)
(default: nil, uses problem_id + letter + ".cc")
WORKFLOW *cp-workflow*
For the sake of consistency and simplicity, cp.nvim extracts contest/problem identifiers from
URLs. This means that, for example, CodeForces/AtCoder contests are configured by
their round id rather than round number. See below.
PLATFORM-SPECIFIC USAGE *cp-platforms*
AtCoder ~
*cp-atcoder*
URL format: https://atcoder.jp/contests/abc123/tasks/abc123_a
In terms of cp.nvim, this corresponds to:
- Platform: atcoder
- Contest ID: abc123
- Problem ID: a
Usage examples: >
:CP atcoder abc123 a " Full setup: problem A from contest ABC123
:CP atcoder abc123 " Contest setup: load contest metadata only
:CP b " Switch to problem B (if contest loaded)
:CP next " Navigate to next problem in contest
<
Codeforces ~
*cp-codeforces*
URL format: https://codeforces.com/contest/1234/problem/A
In terms of cp.nvim, this corresponds to:
- Platform: codeforces
- Contest ID: 1234
- Problem ID: a (lowercase)
Usage examples: >
:CP codeforces 1934 a " Full setup: problem A from contest 1934
:CP codeforces 1934 " Contest setup: load contest metadata only
:CP c " Switch to problem C (if contest loaded)
:CP prev " Navigate to previous problem in contest
<
CSES ~
*cp-cses*
URL format: https://cses.fi/problemset/task/1068
CSES is organized by categories rather than contests. Currently all problems
are grouped under "CSES Problem Set" category.
In terms of cp.nvim, this corresponds to:
- Platform: cses
- Contest ID: "CSES Problem Set" (category)
- Problem ID: 1068 (numeric)
Usage examples: >
:CP cses 1068 " Set up problem 1068 from CSES
:CP 1070 " Switch to problem 1070 (if CSES loaded)
:CP next " Navigate to next problem in CSES
<
COMPLETE WORKFLOW EXAMPLE *cp-example*
Example: Setting up and solving AtCoder contest ABC324
1. Browse to https://atcoder.jp/contests/abc324
2. Set up contest and load metadata: >
:CP atcoder abc324
< This caches all problems (A, B, C, D, E, F, G) for navigation
3. Start with problem A: >
:CP a
< This creates abc324a.cc and scrapes test cases
4. Code your solution, then test: >
:CP run
<
5. If needed, debug: >
:CP debug
<
6. Compare output visually: >
:CP diff
<
7. Move to next problem: >
:CP next
< This automatically sets up problem B
8. Continue solving problems with :CP next/:CP prev navigation
9. Submit solutions on AtCoder website
Example: Quick setup for single Codeforces problem >
:CP codeforces 1933 a " One command setup
:CP run " Test immediately
<
FILE STRUCTURE *cp-files*
cp.nvim creates the following file structure upon problem setup:
{contest_id}{problem_id}.cc " Source file (e.g. abc324a.cc)
build/
{contest_id}{problem_id}.run " Compiled binary
io/
{contest_id}{problem_id}.in " Test input
{contest_id}{problem_id}.out " Program output
{contest_id}{problem_id}.expected " Expected output
The plugin automatically manages this structure and navigation between problems
maintains proper file associations.
SNIPPETS *cp-snippets*
cp.nvim integrates with LuaSnip for automatic template expansion. When you
open a new problem file, type the contest name and press <Tab> to expand.
Built-in snippets include basic C++ templates for each contest type.
Custom snippets can be added via configuration.
HEALTH CHECK *cp-health*
Run |:checkhealth| cp to verify your setup.
vim:tw=78:ts=8:ft=help:norl: