iTranslated by AI
Common Pitfalls When Setting Up the VSCode NeoVim Extension
I usually work using VS Code with the Vim extension installed.
However, I've been feeling frustrated by its sluggish performance.
By the way, here are the reasons why I still stick with VS Code despite that:
- The extensions are convenient
- Pair programming and such are easy
- DevContainers are super useful
- Can enforce the same development environment across the team
- Improves code quality!!
- The environment is automatically set up when the container starts without needing various local configurations
- Can enforce the same development environment across the team
I want to find a way to use VS Code and Vim features while overcoming the sluggishness.
To solve this indulgent problem, I tried introducing VSCode NeoVim!!
(I was inspired after coming across the following article)
However, I ran into some hurdles during the setup process, so I'd like to document them here.
By the way, I decided to postpone the full adoption due to various reasons. It's still in the 0.x version range, so I'm looking forward to further evolution!!
(The reasons for postponing the adoption are listed at the end)
I started using it from August 2021. As expected, it works impressively faster compared to the Vim extension (though it acts a bit weird sometimes...).
Prerequisites
Here is my environment.
I hope this helps those who are struggling with a similar setup.
- macOS Catalina v10.15.6
- VSCode v1.53.0
- Neo Vim extension (asvetliakov.vscode-neovim v0.0.78)
- HomeBrew installed (brew command is available)
Setup Process
Installing NeoVim
This extension cannot operate unless NeoVim is installed on your machine, so first, we will install the NeoVim core.
As of February 11, 2021, you need to install NeoVim version 0.5 or higher.
As of July 16, 2021, with the release of NeoVim version 0.5, installing the nightly version is no longer necessary.
I installed it via Homebrew, specifying the latest version by adding --HEAD when installing.
Also, in my case, an error appeared suggesting that I should install the latest version of luajit as well.
I uninstalled the existing version first and then reinstalled the latest one.
# Uninstall the currently installed version
brew unlink neovim
brew remove neovim
brew remove luajit
brew unlink luajit
# Install the latest version
brew install --HEAD luajit
brew install neovim
Once the installation is complete, verify that version 0.5 or higher is installed using the nvim command.
Also, if you haven't created ~/.config/nvim/init.vim, prepare an empty file.
mkdir -p ~/.config/nvim/
touch init.vim
Installing the VSCode Extension
Install the extension (id: asvetliakov.vscode-neovim).
Next, as described in the official instructions, set the path for NeoVim and the location of the configuration file.
# Check the path to nvim
which nvim
> /usr/local/bin/nvim
In VSCode, press cmd + shift + p, type setting.json, and select Preferences: Open Settings(JSON).
Add the following settings to your JSON file.
(Please adjust the nvim path and configuration file location to match your environment.)
"vscode-neovim.neovimExecutablePaths.darwin": "/usr/local/bin/nvim",
"vscode-neovim.neovimInitVimPaths.darwin": "/Users/xxxx/.config/nvim/init.vim"
Then, after restarting VSCode, I was able to work using Vim keybindings!!
(If you have installed VSCode-Vim, please disable it.)
Installing vim-easymotion
Basically, in this state, if you make plugins available in nvim, you can use them as they are.
(It seems to read your .vimrc.)
While some extensions may not work, the official vim-easymotion plugin reportedly has issues. However, you can use a forked repository's plugin instead.
Speaking honestly, original vim-easymotion works fine and as expected... except one thing: it really replaces your text with markers then restores back. It may work for VIM but for VS Code it leads to broken text and many errors reported while you're jumping. For this reason I created the special vim-easymotion fork which doesn't touch your text and instead use vscode text decorations. Just add my fork to your vim-plug block or by using your favorite vim plugin installer and delete original vim-easymotion. Also overwin motions won't work (obviously) so don't use them. Happy jumping!
In my case, I use dein for plugin management.
If you are using dein, add the following to your init.vim:
if dein#load_state('Users/xxxx/.cache/dein')
call dein#begin('/Users/xxxx/.cache/dein')
" Let dein manage dein
" Required:
call dein#add('/Users/xxxx/.cache/dein/repos/github.com/Shougo/dein.vim')
if exists('g:vscode')
" Use this plugin for VS Code
call dein#add('asvetliakov/vim-easymotion')
" Jump to a location starting with any two characters using 's'
nmap s <Plug>(easymotion-s2)
else
" Use the regular vim-easymotion otherwise (e.g., when launching nvim)
call dein#add('easymotion/vim-easymotion')
nmap s <Plug>(easymotion-overwin-f2)
endif
" Required:
call dein#end()
call dein#save_state()
endif
Despite doing all this
I initially decided against using this extension for the following reasons.
It seemed likely that I wouldn't be able to use official plugins like easy-motion in many cases.-
I felt it was difficult to handle file tree operations in the left pane.With vscode-vim, you can operate it with Vim keybindings.
Regarding the file tree operations, I have added the following settings to my keybinding.json:
{
// Delete files/folders
{
"key": "d",
"command": "deleteFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
},
{
"key": "alt+cmd+backspace",
"command": "-deleteFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
},
// Rename
{
"key": "r",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
},
// Open to side (Split)
{
"key": "v",
"command": "explorer.openToSide",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
},
// Copy
{
"key": "y",
"command": "filesExplorer.copy",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
},
// Paste
{
"key": "p",
"command": "filesExplorer.copfilesExplorer.paste",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
}
}
That being said,
- The performance is fast
- You can leverage your existing Vim assets
These advantages are quite impressive!!
I will keep an eye on its future evolution!!
Discussion