Editing Javascript in vim in Docker

Can neovim + plugins actually functionally beat Visual Studio code?

Published: Sunday, Oct 31, 2021 Last modified: Monday, Apr 8, 2024

I’m spoilt by vim-go, goformat, goimports, a vim IDE that works productively for programming Golang.

Now since I code in Javascript for work, especially for the AWS Cloud Development Kit I want the same features in vim!

The test

UPDATE: This test assumes Javascript, and for proper completion typescript types is more pragmatic.

git clone https://github.com/kaihendry/sam-cdk-app-demo.git

Open lib/aws-sam-cli-cdk-hello-world-stack.js

Formatting

Add an incorrectly formatted console.log, will it get reformatted on save?

Intellisense

Remove runtime: from the lambda.Function constructor. Is the editor (or integrated language server) smart enough to auto complete / suggest that runtime is mandatory and needs to put back?

Next test: Setup a dynamodb table. Can the editor automatically import “@aws-cdk/aws-dynamodb”?

Dockerized neovim

To reproduce issues with my own setup and others, I’m going to try different neovim configurations with the help of Docker containers.

I wouldn’t realistically edit using Docker because it’s far too slow to startup!!

Spacevim

docker run -it --rm spacevim/spacevim

A whole bunch of text errors on startup. Er next!

Sh1d0w/nvim-ide

console.constuctor

console. completion sucks, no autoformatting. Docs are nice though:

Removing runtime, then correctly suggests I need runtime back:

If I save the file without runtime, there is no warning that my program will fail. Tbh VScode doesn’t seem to show my program will fail either missing runtime!

Now adding:

const atable = new dynamodb.Table(this, "hello-world-table", {

I give it 2/5 rating. It’s probably coc-tsserver at fault or probably me.

iimuz/nvim-code

Seems hinged on neovim 0.4x. Moving on..

jcirizar/vim

First to warn me:

[coc.nvim] No ESLint configuration (e.g .eslintrc) found for file: /app/lib/aws-sam-cli-cdk-hello-world-stack.js

Completion seems useless:

Is CoC even working??

leny/docker-neovim

Fails to build:

/bin/sh: pip3: not found

thled/docker-vim-ts

A different sort of python build error!

gcc: fatal error: cannot execute 'cc1plus': execvp: No such file or directory

protometa/editor

Could not get it to open lib/aws-sam-cli-cdk-hello-world-stack.js

quay.io/nvim-lsp/try.nvim:nightly-typescript

mjlbach put me onto his LUA based neovim configuration: https://github.com/nvim-lsp/try.nvim/blob/master/typescript/init.lua

I will probably switch to using https://github.com/nvim-lua/kickstart.nvim without a Docker image.

hrsh7th/nvim-cmp is the Autocompletion plugin, not “nvim-compe” which is deprecated.

hendry/js-nvim

UPDATE: Complete rewrite in https://github.com/kaihendry/nvim

This is my project for my own sanity checking with CoC!

Auto complete on console. is sensible:

Docs are OK

But it doesn’t seem to work on CDK. No docs.

😩

Conclusion

I learned two things about editing Javascript with vim.

First, for a experience comparable to the exemplary vim-go you need to ensure you’re actually working with TypeScript Types. This is actually non-trivial for smaller packages where type definitions are contributed by the community.

Neovim departs from vim with its LUA language integration and its inbuilt language server :LspInfo. I think I will give it a try. I encourage you to try too:

docker run --rm -it --entrypoint=sh -v $(pwd):/src quay.io/nvim-lsp/try.nvim:nightly-typescript

That said, don’t get FOMO. Editing vim without this crazy configuration is actually the better place to be!