A blazing-fast, Rust-powered CLI engine and TUI for solving LeetCode problems natively in Neovim.
Features • Installation • Quick Start • CLI Reference • TUI Keybindings
Warning
This is still a work in progress. Breaking changes to commands and configuration might happen.
- 📌 Overview
- ✨ Features
- 🔧 Prerequisites
- 🛠️ Installation
- ⚙️ Configuration
- ⚡ Quick Start
- 💻 CLI Command Reference
- ⌨️ TUI Keybindings
- 🌐 Supported Languages
- ❓ Troubleshooting & FAQ
- 🤝 Contributing
- 📄 License
leetrs is built for developers who live in the terminal and rely on Neovim. It strips away browser friction by providing a complete LeetCode workflow directly within your terminal:
- Browse & Search: Search problems using an interactive terminal interface (TUI) with fuzzy search, difficulty filters, and topic overlays.
- Fetch & Format: Instantly generate clean Markdown problem descriptions and language-specific code templates.
- Edit in Neovim: Launch Neovim automatically with a vertical split (
vsplit) placing the problem description and code template side-by-side. - Test & Submit: Asynchronously execute sample test cases or submit your solution for full judging, with colorized terminal feedback and runtime statistics.
leetrs.mp4
-
🖥️ Interactive TUI Browser (
leetrs tui/leetrs)- Instant fuzzy search across thousands of LeetCode problems.
- Difficulty filters (Easy, Medium, Hard) and topic tag overlays.
- Visual status indicators for solved status (
ACCEPTANCE), subscription locks, and premium gates. - Quick keys to toggle help popups or open selected problems directly in your system browser.
-
🔑 Intelligent Cookie Authentication (
leetrs auth)- Automatically extracts
LEETCODE_SESSIONandcsrftokencookies from active Chrome or Firefox sessions. - Includes a secure manual token fallback for containerized or custom browser profiles.
- Automatically extracts
-
📝 Frictionless Problem Fetching (
leetrs pick)- Fetch problems using URL slugs (e.g.,
two-sum) or numerical IDs (e.g.,1). - Converts raw LeetCode HTML into clean, wrapped terminal Markdown text.
- Generates idiomatic code files (e.g.,
two_sum.rs,two_sum.py,two_sum.sql) with pre-populated function stubs and metadata headers.
- Fetch problems using URL slugs (e.g.,
-
⚡ Native Neovim Integration
- Seamlessly launches Neovim and opens a side-by-side vertical split (
vsplit). - Problem description sits in the left pane; code solution sits in the right pane.
- Seamlessly launches Neovim and opens a side-by-side vertical split (
-
🧪 Async Testing & Submission Engine (
leetrs test/leetrs submit)- Run code against sample test cases locally without polluting your official submission history.
- Submit directly to LeetCode's judging servers and view real-time judge results, runtime/memory percentiles, and compiler error logs.
| Requirement | Version | Notes |
|---|---|---|
| Neovim | 0.9+ | Must be available as nvim in your $PATH |
| LeetCode Account | — | Required for authentication and submission |
| Google Chrome or Firefox | Any | Used for automatic browser cookie extraction |
| Rust Toolchain | 1.70+ | Required only if installing via Cargo or building from source |
Choose the installation method that best fits your environment.
If you already have Rust and Cargo installed:
cargo install leetrsTip
Ensure ~/.cargo/bin is present in your system $PATH.
Install via Homebrew tap:
brew install shadowmkj/tap/leetrsDownload and install pre-compiled binaries for your platform directly without requiring a Rust installation:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/shadowmkj/leetrs/releases/download/v1.0.18/leetrs-installer.sh | shBuild the latest release binary from source code:
# 1. Clone the repository
git clone https://github.com/shadowmkj/leetrs.git
cd leetrs
# 2. Build optimized release binary
cargo build --release
# 3. Copy binary to executable PATH
cp target/release/leetrs ~/.cargo/bin/
# — or —
sudo cp target/release/leetrs /usr/local/bin/
# 4. Verify installation
leetrs --versionleetrs uses a TOML configuration file to customize editor launcher commands, default languages, and display settings.
The configuration file (config.toml) is stored in standard system directories:
| OS | Default Path |
|---|---|
| Linux / macOS | ~/.config/leetrs/config.toml |
| Windows | %APPDATA%\leetrs\config.toml |
Note
The configuration file and parent directories are automatically created on first execution if they do not exist.
| Option | Type | Default | Description |
|---|---|---|---|
editor |
string |
"nvim" |
Command executed when picking a problem. Use "nvim" or "vim" for terminal split, or "code" for VS Code. |
language |
string |
"python3" |
Default language for code stub generation ("rust", "python3", "pythondata", "mysql", "postgresql"). |
show_description |
boolean |
true |
When true, opens problem description alongside the code stub in split view. |
# ~/.config/leetrs/config.toml
editor = "nvim"
language = "rust"
show_description = trueFollow these steps to get up and running:
# 1. Authenticate with LeetCode (extracts browser cookies automatically)
leetrs auth
# 2. Check authentication status
leetrs status
# 3. Launch the interactive TUI problem browser
leetrs tui
# 4. Alternatively, pick a problem directly by slug or numeric ID
leetrs pick two-sum
leetrs pick 1
# 5. Solve the problem in Neovim, then test against example testcases
leetrs test two_sum.rs
# 6. Submit solution for full judging
leetrs submit two_sum.rsleetrs provides a suite of CLI subcommands:
| Subcommand | Arguments / Flags | Description |
|---|---|---|
auth |
— | Interactively extracts cookies from Chrome/Firefox or accepts manual tokens. |
tui |
[language] |
Launches the interactive TUI problem browser. Optionally set temporary language override. |
pick |
<identifier> [language] [-p, --preview] |
Fetches problem, creates files, and opens editor. Identifier can be a slug (two-sum) or ID (1). --preview prints markdown to stdout. |
test |
<file> |
Tests local solution file against sample test cases without official submission. |
submit |
<file> |
Submits solution file to LeetCode for full judging and statistics. |
status |
— | Displays active authentication state and token information. |
completion |
<shell> |
Generates shell autocomplete scripts (bash, zsh, fish). |
When navigating the interactive TUI (leetrs tui), the following keybindings are available:
| Keybinding | Action |
|---|---|
j / Down |
Move selection down one item |
k / Up |
Move selection up one item |
g g |
Jump to top of problem list |
G |
Jump to bottom of problem list |
Ctrl+d |
Page down |
Ctrl+u |
Page up |
Enter |
Pick selected problem and open in configured editor |
o |
Open selected problem in default web browser |
| Keybinding | Action |
|---|---|
/ |
Focus search bar (fuzzy search by title / ID) |
1 |
Easy Problems |
2 |
Medium Problems |
3 |
Hard Problems |
4 |
Any difficulty |
t |
Open topic overlay filter modal |
Tab |
Cycle focus between UI components |
? |
Toggle interactive Help overlay |
Esc |
Clear search filter / exit edit mode / dismiss popup |
q |
Quit TUI |
leetrs supports major LeetCode programming languages, automatically inferring extensions and comment formats:
| Language Name | LeetCode Slug | File Extension | Meta Header Comment Style |
|---|---|---|---|
| Rust | rust |
.rs |
// id=1 slug=two-sum lang=rust |
| Python 3 | python3 |
.py |
# id=1 slug=two-sum lang=python3 |
| Pandas | pythondata |
.py |
# id=1 slug=two-sum lang=pythondata |
| MySQL | mysql |
.sql |
# id=1 slug=two-sum lang=mysql |
| PostgreSQL | postgresql |
.sql |
-- id=1 slug=two-sum lang=postgresql |
Automatic cookie extraction fails during leetrs auth
- Ensure you are logged into leetcode.com in your selected browser (Chrome or Firefox).
- If using containerized browser packages (such as Snap or Flatpak on Linux) or custom profile paths, select "Paste tokens manually" during
leetrs auth. - Tokens can be obtained from your browser's Developer Tools (
F12→ Application/Storage → Cookies →leetcode.com): copyLEETCODE_SESSIONandcsrftoken.
Neovim fails to launch after leetrs pick
- Verify that Neovim is installed and accessible as
nvimin your system$PATH:which nvim
- If using another editor, set
editor = "code"or your preferred editor binary in~/.config/leetrs/config.toml.
How do I refresh cached problem lists or user profile data?
leetrscaches problem metadata locally in your user data directory (~/.local/share/leetrs/or OS equivalent).- If problem cache becomes corrupted, delete the cache file to trigger a fresh sync on next run:
rm -rf ~/.local/share/leetrs/data.json
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct, development setup, and pull request workflow.
- Fork the Repository
- Create your Feature Branch (
git checkout -b feature/amazing-feature) - Commit your Changes (
git commit -m "feat: add amazing feature") - Push to the Branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more details.
Developed with ❤️ by shadowmkj.