Solve LeetCode problems in Vim!
This Vim plugin is a fork of ianding1/leetcode.vim which is inspired by skygragon/leetcode-cli.
Attention: Recently LeetCode used Google reCAPTCHA to enhance security, prohibiting automatic login through LeetCode API.
The new login procedure needs you to login in your browser first so that neuleetcode.vim can read the LeetCode session cookie from the browser's cookie storage.
Supported browsers are: Chrome, Firefox. Safari is not supported yet.
The one-time setup:
- Install keyring and browser-cookie3:
pip3 install keyring browser-cookie3 --user
- Set
g:leetcode_browser
to'chrome'
or'firefox'
.
Thanks @zhuopro (see #25) for his brilliant idea!
- Vim with
+python3
feature is required. Install the pynvim package for Neovim:
pip3 install pynvim --user
- Install keyring and browser-cookie3:
pip3 install keyring browser-cookie3 --user
- Install the plugin:
Plug 'mbledkowski/neuleetcode.vim'
:LeetCodeList
: browse the problems.:LeetCodeTest
: run the code with the default test case.:LeetCodeSubmit
: submit the code.:LeetCodeSignIn
: manually sign in.
neuleetcode.vim doesn't bind any key mappings by default. Put the following lines to your .vimrc to set up the key mappings.
nnoremap <leader>ll :LeetCodeList<cr>
nnoremap <leader>lt :LeetCodeTest<cr>
nnoremap <leader>ls :LeetCodeSubmit<cr>
nnoremap <leader>li :LeetCodeSignIn<cr>
When non-zero, use LeetCode China accounts instead.
Default value is 0
.
The preferred programming language.
Values: 'c'
, 'cpp'
, 'csharp'
, 'java'
, 'kotlin'
, 'scala'
, 'python'
, 'python3'
, 'ruby'
, 'javascript'
, 'typescript'
, 'php'
,
'swift'
, 'rust'
, 'golang'
, 'erlang'
, 'racket'
, 'erlang'
.
Default value is 'cpp'
.
Set to the browser that stores the LeetCode session cookie.
Values: 'disabled'
, 'chrome'
, 'firefox'
Default value is 'disabled'
.
Hide the paid only problems on the list.
Default value is 0
.
Hide the topics section.
Default value is 0
Hide the companies section.
Default value is 0
Set the problemset to get from leetcode.
Default value is all
Ubuntu users might see the error message below when signing in.
raise InitError("Failed to unlock the collection!")
keyring.errors.InitError: Failed to unlock the collection!
It's caused by the misconfiguration of python-keyring. One way to fix it is to create a file ~/.local/share/python_keyring/keyringrc.cfg
with the following content:
[backend]
default-keyring=keyring.backends.Gnome.Keyring
According to issue #5, if the email address is not active, then you can only login and download problems, but cannot test and submit any code.
This solution worked for me:
pip3 install --upgrade keyrings.alt