111 lines
4 KiB
HTML
111 lines
4 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<link rel="stylesheet" href="/styles/common.css" />
|
|
<link rel="stylesheet" href="/styles/post.css" />
|
|
<link rel="icon" type="image/webp" href="/public/logo.webp" />
|
|
<title>my cp setup</title>
|
|
</head>
|
|
<body class="graph-background">
|
|
<site-header></site-header>
|
|
<main class="main">
|
|
<div class="post-container">
|
|
<header class="post-header">
|
|
<h1 class="post-title">my cp setup</h1>
|
|
<p class="post-meta">
|
|
<time datetime="2025-04-15">15/04/2025</time>
|
|
</p>
|
|
</header>
|
|
<article class="post-article">
|
|
<p>
|
|
Source code
|
|
<a
|
|
href="https://github.com/barrett-ruth/dots/blob/main/nvim/lua/cp.lua"
|
|
target="_blank"
|
|
>here</a
|
|
>.
|
|
</p>
|
|
<h2>my goals</h2>
|
|
<p>
|
|
I wanted the following features in my competitive programming (cp)
|
|
setup:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
<u>Flexibility</u>: support various environments (codeforces,
|
|
USACO, cses, etc.) with ease
|
|
</li>
|
|
<li>
|
|
<u>Speed</u>: instantaneous, non-blocking running/debugging;
|
|
automatic environment configuration and easy code testing
|
|
</li>
|
|
<li>
|
|
<u>Editor-Agnostic</u>: while I do provide first-in-class NeoVim
|
|
integration for my setup, it should be easily portable to
|
|
<i>any</i> os/editor.
|
|
</li>
|
|
</ul>
|
|
<h2>the solution</h2>
|
|
<p>
|
|
Some (POSIX-compliant, of course) scripts and a
|
|
<code>makefile</code> are more than enough. I created the following
|
|
intuitive way to interact with my CP setup:
|
|
</p>
|
|
<ol>
|
|
<li>
|
|
<code>make setup</code>: populate the environment with
|
|
configurations in <code>~/.config/cp-template</code> for
|
|
<code>clang-format</code> and <code>clangd</code>
|
|
</li>
|
|
<li><code>make run file</code></li>
|
|
<li><code>make debug file</code></li>
|
|
<li><code>make clean</code></li>
|
|
</ol>
|
|
<p>
|
|
That's it. The <code>makefile</code> relies on some scripts that
|
|
compile code and run the corresponding executables.
|
|
</p>
|
|
<h2>neovim integration</h2>
|
|
<div style="display: flex; justify-content: center">
|
|
<img
|
|
width="80%"
|
|
src="/public/posts/my-cp-setup/cp-setup.webp"
|
|
alt="screenshot of my neovim competitive programming setup"
|
|
/>
|
|
</div>
|
|
<p>
|
|
Leveraging
|
|
<a href="https://github.com/L3MON4D3/LuaSnip" target="_blank"
|
|
>LuaSnip</a
|
|
>, a custom <code>CP</code> user command, and some scripting for
|
|
window management and asynchronous jobs, I'm able to:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
Asynchronously format, run, and debug code (<code
|
|
>:h vim.system</code
|
|
>)
|
|
</li>
|
|
<li>Use a three-window (input, output, and code) view</li>
|
|
<li>Toggle between problems instantly (yes, the windows update)</li>
|
|
<li>
|
|
Automatically populate my coding buffers with competition-specific
|
|
templates (i.e. USACO, CSES, etc.)
|
|
</li>
|
|
<li>Run the code from the CLI in less than a second</li>
|
|
<li>
|
|
Easily tweak and change the setup—there's absolutely nothing
|
|
fancy.
|
|
</li>
|
|
</ul>
|
|
</article>
|
|
</div>
|
|
</main>
|
|
<site-footer></site-footer>
|
|
<script src="/scripts/common.js"></script>
|
|
<script src="/scripts/post.js"></script>
|
|
</body>
|
|
</html>
|