Solve LeetCode problems in Vim!
Solve LeetCode problems in Vim!
This Vim plugin 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 leetcode.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:
shell pip3 install keyring browser-cookie3 --user
g:leetcode_browserto
'chrome'or
'firefox'.
Thanks @zhuopro (see #25) for his brilliant idea!
+python3feature is required. Install the pynvim package for Neovim:
sh pip3 install pynvim --user
sh pip3 install keyring browser-cookie3 --user
vim Plug 'ianding1/leetcode.vim'
:LeetCodeList: browse the problems.
:LeetCodeTest: run the code with the default test case.
:LeetCodeSubmit: submit the code.
:LeetCodeSignIn: manually sign in.
leetcode.vim doesn't bind any key mappings by default. Put the following lines to your .vimrc to set up the key mappings.
nnoremap ll :LeetCodeList nnoremap lt :LeetCodeTest nnoremap ls :LeetCodeSubmit nnoremap li :LeetCodeSignIn
g:leetcode_china
When non-zero, use LeetCode China accounts instead.
Default value is
0.
g:leetcode_solution_filetype
The preferred programming language.
Values:
'cpp',
'java',
'python',
'python3',
'csharp',
'javascript',
'ruby',
'swift',
'golang',
'scala',
'kotlin',
'rust'.
Default value is
'cpp'.
g:leetcode_browser
Set to the browser that stores the LeetCode session cookie.
Values:
'disabled',
'chrome',
'firefox'
Default value is
'disabled'.
g:leetcode_hide_paid_only
Hide the paid only problems on the list.
Default value is
0.
g:leetcode_hide_topics
Hide the topics section.
Default value is
0
g:leetcode_hide_companies
Hide the companies section.
Default value is
0
g:leetcode_problemset
Set the problemset to get from leetcode.
Default value is
all
Ubuntu users might see the error message below when signing in.
text 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.cfgwith the following content:
[backend] default-keyring=keyring.backends.Gnome.Keyring
~~Once you sign in on your browser in LeetCode website, the LeetCode session in Vim get expired immediatelly. Then you need to sign in again in Vim before doing other things.~~ (No longer having this problem)
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:
shell pip3 install --upgrade keyrings.alt