Fork me on GitHub

SpaceVim

A community-driven vim distribution


Home | About | Documentation | Development | Community | Sponsors


Blogs » Use Vim as a JavaScript IDE

This is a general guide for using SpaceVim as a JavaScript IDE, including layer configuration and usage. Each of the following sections will be covered:

Enable language layer

By default lang#javascript layer is not loaded. To add JavaScript language support in SpaceVim, you need to enable the lang#javascript layer. Press SPC f v d to open SpaceVim configuration file, and add following configuration:

[[layers]]
  name = "lang#javascript"

for more info, you can read the lang#javascript layer documentation.

Code completion

lang#javascript layer will load the javascript plugins automatically, unless overriden in your init.toml. The completion menu will be opened as you type.

jside

Syntax linting

The checkers layer is enabled by default. This layer provides asynchronous syntax linting via neomake. It will run eslint asynchronously.

To install eslint, just run following command in terminal.

npm install -g eslint-cli

eslint

Jump to test file

SpaceVim use built-in plugin to manager the files in a project, you can add a .project_alt.json to the root of your project with following content:

{
  "src/*.js": {"alternate": "test/{}.js"},
  "test/*.js": {"alternate": "src/{}.js"}
}

with this configuration, you can jump between the source code and test file via command :A.

running code

To run code in current buffer, you can press SPC l r, and a split windows will be openen, the output will be shown in this windows. It is running asynchronously, and will not block your vim.

jsrunner

Code formatting

The format layer is also enabled by default, with this layer you can use key binding SPC b f to format current buffer. Before using this feature, please install js-beautify.

npm install -g js-beautify

REPL support

Start a node -i inferior REPL process with SPC l s i. After the REPL process has been started. you can send code to inferior process, all key bindings are begin with SPC l s prefix, including sending line, sending selection or even send whole buffer.

jsrepl

Hosted on GitHub, Help improve this page — Theme by mattgraham,