A Neovim plugin enabling you to solve LeetCode problems.
leetcode.nvim
🇺🇸 English, 🇨🇳 简体中文
https://github.com/kawre/leetcode.nvim/assets/69250723/aee6584c-e099-4409-b114-123cb32b7563
Caution
此插件仅与Java进行了专门测试。
如果您在使用其他语言时遇到任何错误,请打开一个问题报告它们。
✨ 特性
-
📌 直观的仪表板,轻松导航 leetcode.nvim 内
-
😍 更好的可读性的问题描述格式
-
🔀 支持每日和随机问题
-
💾 缓存以优化性能
📬 环境要求
-
Neovim >= 0.9.0
-
nvim-treesitter (可选,但强烈推荐) 用于格式化问题描述。 确保安装
html解析器。 -
nvim-notify (可选)
-
Nerd Font & nvim-web-devicons (可选)
📦 安装
{
"kawre/leetcode.nvim",
build = ":TSUpdate html",
dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim", -- telescope 所需
"MunifTanjim/nui.nvim",
-- 可选
"nvim-treesitter/nvim-treesitter",
"rcarriga/nvim-notify",
"nvim-tree/nvim-web-devicons",
},
opts = {
-- 配置放在这里
cn = {
enabled = true,
},
},
}
🛠️ 配置
要查看完整的配置类型,请参见 template.lua
⚙️ 默认配置
{
---@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 lc.storage
storage = {
home = vim.fn.stdpath("data") .. "/leetcode",
cache = vim.fn.stdpath("cache") .. "/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,
}
arg
Neovim 的参数
---@type string
arg = "leetcode.nvim"
有关更多信息,请参见 usage
lang
会话开始时使用的语言
---@type lc.lang
lang = "cpp"
| Language | lang |
|---|---|
| C++ | cpp |
| Java | java |
| Python | python |
| Python3 | python3 |
| C | c |
| C# | csharp |
| JavaScript | javascript |
| TypeScript | typescript |
| PHP | php |
| Swift | swift |
| Kotlin | kotlin |
| Dart | dart |
| Go | golang |
| Ruby | ruby |
| Scala | scala |
| Rust | rust |
| Racket | racket |
| Erlang | erlang |
| Elixir | elixir |
| Bash | bash |
cn
将 leetcode.com 替换为 leetcode.cn
cn = { -- leetcode.cn
enabled = false, ---@type boolean
translator = true, ---@type boolean
translate_problems = true, ---@type boolean
},
storage
存储目录
---@type lc.storage
storage = {
home = vim.fn.stdpath("data") .. "/leetcode",
cache = vim.fn.stdpath("cache") .. "/leetcode",
},
logging
是否记录 leetcode.nvim 状态通知
---@type boolean
logging = true
injector
在你的答案前后注入额外代码,注入的代码不会被提交或测试。
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
在指定事件上执行的函数列表
hooks = {
---@type fun()[]
LeetEnter = {},
---@type fun(question: lc.ui.Question)[]
LeetQuestionNew = {},
},
image support
是否使用 image.nvim 渲染问题描述中的图片
Warning
启用此选项将禁用问题描述的换行,因为 https://github.com/3rd/image.nvim/issues/62#issuecomment-1778082534
---@type boolean
image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行
📋 命令
Leet 打开菜单仪表板
-
menu与Leet相同 -
console打开当前打开问题的控制台弹出窗口 -
info打开包含当前打开问题信息的弹出窗口 -
tabs打开所有当前打开问题选项卡的选择器 -
yank复制当前问题的解决方案 -
lang打开更改当前问题语言的选择器 -
run运行当前打开的问题 -
test与Leet run相同 -
submit提交当前打开的问题 -
random打开一个随机问题 -
daily打开今天的问题 -
list打开问题列表选择器 -
open在默认浏览器中打开当前问题 -
reset还原到默认的代码模版 -
last_submit检索上次提交的代码,用于当前问题 -
restore尝试恢复默认问题布局 -
desc切换问题描述-
toggle与Leet desc相同 -
stats切换描述统计可见性
-
-
cookie-
update打开提示输入新 cookie -
delete注销
-
-
cacheupdate更新缓存
可以带有可选参数。要堆叠参数值,请使用 , 将它们分隔开
-
Leet listLeet list status=<status> difficulty=<difficulty> -
Leet randomLeet random status=<status> difficulty=<difficulty> tags=<tags>
🚀 使用方法
该插件可以通过两种方式启动:
-
要启动 leetcode.nvim,只需将
arg作为 第一个且唯一 Neovim 参数传递nvim leetcode.nvim -
(实验性) 另外,您可以使用
:Leet命令在您喜欢的仪表板插件中打开 leetcode.nvim。唯一的要求是 Neovim 不能有任何列出的缓冲区打开。
切换问题
要在问题之间切换,请使用 Leet tabs。
登录
使用 leetcode.nvim 必须 登录
https://github.com/kawre/leetcode.nvim/assets/69250723/b7be8b95-5e2c-4153-8845-4ad3abeda5c3
🍴 示例
💤 使用 lazy.nvim 进行延迟加载
Warning
选择其中任一选项将由于延迟加载而使另一启动方法不可用。
-
使用
arglocal leet_arg = "leetcode.nvim"{ "kawre/leetcode.nvim", lazy = leet_arg ~= vim.fn.argv()[1], opts = { arg = leet_arg }, } -
使用
:Leet{ "kawre/leetcode.nvim", cmd = "Leet", }