A Neovim plugin for competitive programming that provides a streamlined coding environment with automatic I/O handling.
- 🎯 Split Layout: Dedicated panes for code (left) and I/O (right: input top, output bottom)
- ⚡ Quick Execution: Run your code with
:Cpru- no need forfreopen()in your code - 📝 Templates: Insert competitive programming templates with
:Cpt - 🔄 Temporary I/O: Input/output buffers are temporary - no cluttered files
- 🌲 Smart Navigation: Files from nvim-tree always open in the code pane
- 🎨 Multi-language: Support for C++, C, Java, and Python
Using lazy.nvim
{
"yourusername/cpmode.nvim",
config = function()
require('cpmode').setup({
io_pane_width = 40, -- Width of I/O pane (percentage)
input_height = 50, -- Height of input pane (percentage)
timeout = 5, -- Execution timeout in seconds
})
end,
keys = {
{ "<leader>cp", "<cmd>Cpm<cr>", desc = "Toggle CP Mode" },
{ "<leader>cr", "<cmd>Cpru<cr>", desc = "Run CP Program" },
{ "<leader>cx", "<cmd>Cpre<cr>", desc = "Reset CP I/O" },
{ "<leader>ct", "<cmd>Cpt<cr>", desc = "Insert CP Template" },
},
}Using packer.nvim
use {
'yourusername/cpmode.nvim',
config = function()
require('cpmode').setup()
end
}Using vim-plug
Plug 'yourusername/cpmode.nvim'
lua << EOF
require('cpmode').setup()
EOF- Open a
.cppfile (or other supported language) - Run
:Cptto insert a competitive programming template - Run
:Cpmto activate the split layout - Write your code in the left pane
- Add test input in the top-right pane
- Run
:Cpruto execute and see output in the bottom-right pane
| Command | Description |
|---|---|
:Cpm |
Toggle competitive programming layout |
:Cpru |
Compile and run the current file with I/O |
:Cpt |
Insert language-specific template at cursor |
:Cpre |
Clear input and output buffers |
require('cpmode').setup({
-- Width of the I/O pane (percentage of screen)
io_pane_width = 40,
-- Height of input pane relative to I/O pane (percentage)
input_height = 50,
-- Program execution timeout (seconds)
timeout = 5,
-- Compilation commands
compile_commands = {
cpp = "g++ -std=c++17 -O2 -Wall %s -o %s",
c = "gcc -std=c11 -O2 -Wall %s -o %s",
java = "javac %s",
python = nil,
},
-- Run commands
run_commands = {
cpp = "./%s",
c = "./%s",
java = "java %s",
python = "python3 %s",
},
})You can customize templates for each language:
require('cpmode').setup({
templates = {
cpp = [[
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}]],
python = [[
def solve():
# Your code here
pass
if __name__ == "__main__":
solve()
]],
},
})# 1. Create/open a C++ file
nvim solution.cpp
# 2. Insert template
:Cpt
# 3. Activate CP mode
:Cpm
# 4. Write your solution in the left pane
# 5. Add test input in the top-right pane
# 6. Run your code
:Cpru
# 7. View output in the bottom-right pane- Neovim >= 0.8.0
- Compiler/interpreter for your language:
- C++:
g++orclang++ - C:
gccorclang - Java:
javacandjava - Python:
python3
- C++:
- Unix-like system (Linux, macOS) or Windows with proper PATH setup
- For timeout feature:
timeoutcommand (Unix) or equivalent
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by competitive programming workflows
- Built for the Neovim community
If you encounter any issues or have suggestions, please open an issue.
Note: This plugin works best with nvim-tree and alpha-nvim, but they are not required.
### `LICENSE`
MIT License
Copyright (c) 2025 [Your Name]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### `.gitignore`
*.lua~
.DS_Store Thumbs.db
*.swp *.swo *~
/test/