Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
124 lines
3.5 KiB
Markdown
124 lines
3.5 KiB
Markdown
---
|
|
title: "Use Vim as a JavaScript IDE"
|
|
categories: [tutorials, blog]
|
|
image: https://img.spacevim.org/51976034-add03380-24be-11e9-84b5-245432e7f933.png
|
|
description: "A general guide for using SpaceVim as JavaScript IDE, including layer configuration, requiems installation and usage."
|
|
type: article
|
|
comments: true
|
|
commentsID: "Use Vim as a JavaScript IDE"
|
|
language: JavaScript
|
|
---
|
|
|
|
# [Blogs](../blog/) >> 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:
|
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
- [Enable language layer](#enable-language-layer)
|
|
- [Code completion](#code-completion)
|
|
- [Syntax linting](#syntax-linting)
|
|
- [Jump to test file](#jump-to-test-file)
|
|
- [running code](#running-code)
|
|
- [Code formatting](#code-formatting)
|
|
- [REPL support](#repl-support)
|
|
|
|
<!-- vim-markdown-toc -->
|
|
|
|
### 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:
|
|
|
|
```toml
|
|
[[layers]]
|
|
name = "lang#javascript"
|
|
```
|
|
|
|
for more info, you can read the [lang#javascript](../layers/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.
|
|
|
|

|
|
|
|
### Syntax linting
|
|
|
|
The checkers layer is enabled by default. This layer provides asynchronous syntax linting via [neomake](https://github.com/neomake/neomake).
|
|
It will run [eslint](https://eslint.org/) asynchronously.
|
|
|
|
To install eslint, just run following command in terminal.
|
|
|
|
```sh
|
|
npm install -g eslint
|
|
```
|
|
|
|
Create .eslintrc.json in $HOME directory
|
|
|
|
```
|
|
touch ~/.eslintrc.json
|
|
```
|
|
|
|
Add basic configuration that can be extended based on specific needs
|
|
|
|
```
|
|
{
|
|
"env": {
|
|
"browser": true,
|
|
"commonjs": true,
|
|
"es2021": true
|
|
},
|
|
"extends": "eslint:recommended",
|
|
"parserOptions": {
|
|
"ecmaVersion": 13
|
|
},
|
|
"rules": {
|
|
}
|
|
}
|
|
```
|
|
|
|

|
|
|
|
### Jump to test file
|
|
|
|
SpaceVim use built-in plugin to manage the files in a project,
|
|
you can add a `.project_alt.json` to the root of your project with following content:
|
|
|
|
```json
|
|
{
|
|
"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 window
|
|
will be opened, the output will be shown in this window.
|
|
It is running asynchronously, and will not block your vim.
|
|
|
|

|
|
|
|
### 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.
|
|
|
|
```sh
|
|
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 begins with `SPC l s` prefix, including sending line, sending selection or even
|
|
send whole buffer.
|
|
|
|

|