VSCode Neovim setup

I recently switched over to using the vscode-neovim extension for VSCode.

What wasn’t obvious though was how to get a plugin manager and plugins / vim customisations working.

I’ll add here quickly my plugins setup as I’m using vim-surround, and a bunch of Tim Pope plugins:

I’m on Linux / Ubuntu 22.04, with nvim installed via apt with ppa-neovim/unstable – you need this to get the current required nvim v0.8+.

I moved from Vim to Neovim and I still use my .vimrc and amazingly this kind of setup seems to work with vscode-neovim too.

As per the :help nvim-from-vim have the following ~/.config/nvim/init.vim:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
if exists('g:vscode')
" VSCode extension
source ~/.vimrc.vscode
" ordinary Neovim
source ~/.vimrc
view raw init.vim hosted with ❤ by GitHub

This happily loads my ~/.vimrc file for terminal nvim and then loads ~/.vimrc.vscode for vscode-neovim – which also appears to load:

  1. It sets my leader to <space>
  2. It loads Plug
  3. It loads my custom key mappings
  4. It loads vim-surround and and vim-repeat
    1. I know it loads these because I have a command map <leader>' ysiw'
    2. This puts single quotes around the current word
    3. This works (so vim-surround works)
    4. I can then ‘repeat’ my adding quotes with . which means vim-repeat is working in combination with it.

I have massively stripped my .vimrc file down and renamed it to ~/.vimrc.vscode:

let data_dir=has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim –create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall sync | source $MYVIMRC
set nocompatible
call plug#begin('~/.vim/bundle')
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-commentary'
call plug#end()
nnoremap <space> <nop>
let mapleader="\<space>"
let g:mapleader="\<space>"
autocmd FileType php setlocal commentstring=\/\/\ %s
autocmd FileType javascript setlocal commentstring=\/\/\ %s
autocmd FileType reason setlocal commentstring=\/\/\ %s
autocmd FileType dosbatch setlocal commentstring=rem\ %s
autocmd FileType rust setlocal commentstring=//\ %s
map <leader>' ysiw'
map <leader>" ysiw"
map <leader>; A;<esc>
map <silent> <leader><cr> :nohlsearch<cr>
nnoremap <leader>bb :buffers<cr>:b<space>
map <leader>s :w<cr>
view raw .vscode.vimrc hosted with ❤ by GitHub

Some interesting things that do work:

  • vim-plug works!
  • Basically it’s just really really cool that you can use a .vimrc
    • This means almost tons of remaps should work
  • :buffers works but it’s kind of ugly
  • :nohlsearch works (removing the highlight)
  • :vsplit works and moving with <C-w>[hjkl]

Lots of things don’t work like:

  • I got a conflict between my vim-plug config for VSCode and for neovim
    • By running :PlugClean inside VSCode this wiped all my neovim vim-plug directories
    • Effectively I think this means its better to maintain your plugins via neovim
    • Then use a subset within VSCode
  • preview, quickfix and location windows
  • I don’t think :windo diffthis works
  • You have the same problem as with VSCode Vim that undoing all changes doesn’t get rid of the file ‘dirty bit’ so you have to save it to fully undo
  • :bd doesn’t work as you expect – you need to use :q instead
  • I found the :e <type file path> didn’t work with auto-complete beyond the current directory – just use Ctrl + P instead.
  • There is no command history – you can’t use the up arrow to go to previous ex commands that you typed – I’m surprised about this so maybe there is a config setting somewhere Ctrl + N/Ctrl + P are used instead of up/down

I’ll try to list more as I go further.

For a couple of hours spent setting it up and to have 90% of the plugins I need working is really great.

Until I can get fugitive and vim diffs (in combination with fugitive) working I will still want to use terminal nvim, but that fits quite easily into my coding process for now.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.