A Neovim plugin enabling you to solve LeetCode problems.
Clone โพ
| 13 B | |
| 379 B | |
| 174 B | |
| 1.0 KB | |
| 7.2 KB | |
| 7.0 KB |
๐จ leetcode.nvim is currently in the alpha stage of development ๐จ
leetcode.nvim
๐ฅ Solve LeetCode problems within Neovim ๐ฅ
๐บ๐ธ English, ๐จ๐ณ ็ฎไฝไธญๆ
https://github.com/kawre/leetcode.nvim/assets/69250723/aee6584c-e099-4409-b114-123cb32b7563
โจ Features
-
๐ an intuitive dashboard for effortless navigation within leetcode.nvim
-
๐ question description formatting for a better readability
-
๐ support for daily and random questions
-
๐พ caching for optimized performance
๐ฌ Requirements
-
Neovim >= 0.9.0
-
nvim-treesitter (optional, but highly recommended) used for formatting the question description. Make sure to install the parser for
html. -
nvim-notify (optional)
-
Nerd Font & nvim-web-devicons (optional)
๐ฆ Installation
{
"kawre/leetcode.nvim",
build = ":TSUpdate html",
dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim", -- required by telescope
"MunifTanjim/nui.nvim",
-- optional
"nvim-treesitter/nvim-treesitter",
"rcarriga/nvim-notify",
"nvim-tree/nvim-web-devicons",
},
opts = {
-- configuration goes here
},
}
๐ ๏ธ Configuration
To see full configuration types see template.lua
โ๏ธ default configuration
{
---@type string
arg = "leetcode.nvim",
---@type lc.lang
lang = "cpp",
cn = { -- leetcode.cn
enabled = false, ---@type boolean
translator = true, ---@type boolean
translate_problems = true, ---@type boolean
},
---@type string
directory = vim.fn.stdpath("data") .. "/leetcode/",
---@type boolean
logging = true,
injector = {}, ---@type table<lc.lang, lc.inject>
cache = {
update_interval = 60 * 60 * 24 * 7, ---@type integer 7 days
},
console = {
open_on_runcode = true, ---@type boolean
dir = "row", ---@type lc.direction
size = { ---@type lc.size
width = "90%",
height = "75%",
},
result = {
size = "60%", ---@type lc.size
},
testcase = {
virt_text = true, ---@type boolean
size = "40%", ---@type lc.size
},
},
description = {
position = "left", ---@type lc.position
width = "40%", ---@type lc.size
show_stats = true, ---@type boolean
},
hooks = {
---@type fun()[]
LeetEnter = {},
---@type fun(question: lc.ui.Question)[]
LeetQuestionNew = {},
},
keys = {
toggle = { "q", "<Esc>" }, ---@type string|string[]
confirm = { "<CR>" }, ---@type string|string[]
reset_testcases = "r", ---@type string
use_testcase = "U", ---@type string
focus_testcases = "H", ---@type string
focus_result = "L", ---@type string
},
---@type boolean
image_support = false, -- setting this to `true` will disable question description wrap
}
arg
Argument for Neovim
---@type string
arg = "leetcode.nvim"
See usage for more info
lang
Language to start your session with
---@type lc.lang
lang = "cpp"
cn
Use leetcode.cn instead of leetcode.com
cn = { -- leetcode.cn
enabled = false, ---@type boolean
translator = true, ---@type boolean
translate_problems = true, ---@type boolean
},
directory
Where to store leetcode.nvim data
---@type string
directory = vim.fn.stdpath("data") .. "/leetcode/"
logging
Whether to log leetcode.nvim status notifications
---@type boolean
logging = true
injector
Inject code before or after your solution, injected code won't be submitted or run.
injector = { ---@type table<lc.lang, lc.inject>
["cpp"] = {
before = { "#include <bits/stdc++.h>", "using namespace std;" },
after = "int main() {}",
},
["java"] = {
before = "import java.util.*;",
},
}
hooks
List of functions that get executed on specified event
hooks = {
---@type fun()[]
LeetEnter = {},
---@type fun(question: lc.ui.Question)[]
LeetQuestionNew = {},
},
image support
Whether to render question description images using image.nvim
---@type boolean
image_support = false, -- setting this to `true` will disable question description wrap
๐ Commands
Leet opens menu dashboard
-
menusame asLeet -
consoleopens console pop-up for currently opened question -
infoopens a pop-up containing information about the currently opened question -
tabsopens a picker with all currently opened question tabs -
langopens a picker to change the language of the current question -
runrun currently opened question -
testsame asLeet run -
submitsubmit currently opened question -
randomopens a random question -
dailyopens the question of today -
listopens a problemlist picker -
desctoggle question description-
togglesame asLeet desc -
statstoggle description stats visibility
-
-
cookie-
updateopens a prompt to enter a new cookie -
deletesign-out
-
-
cacheupdateupdates cache
Leet list
Can take optional arguments. To stack argument values separate them by a ,
Leet list status=<status> difficulty=<difficulty>
๐ Usage
This plugin is meant to be used within a fresh Neovim instance.
Meaning that to launch leetcode.nvim you have to pass
arg as the first and only Neovim argument
nvim leetcode.nvim
Switching between questions
To switch between questions, use Leet tabs
Sign In
It is required to be signed-in to use leetcode.nvim
https://github.com/kawre/leetcode.nvim/assets/69250723/b7be8b95-5e2c-4153-8845-4ad3abeda5c3
๐ด Recipes
lazy loading
- proper lazy loading with lazy.nvim
local leet_arg = "leetcode.nvim"
return {
"kawre/leetcode.nvim",
...
lazy = leet_arg ~= vim.fn.argv()[1],
opts = {
arg = leet_arg,
},
...
}
โ Todo
- [x] CN version
- [x] Statistics menu page
- [ ] Docs
- [x] Hints pop-up