2019-02-12 14:18:44 +08:00
---
title: "Use Vim as a Perl IDE"
categories: [tutorials, blog]
2023-07-05 11:50:23 +08:00
image: https://img.spacevim.org/52611209-54550500-2ebf-11e9-9b9f-f697a0db52a3.png
2020-05-10 14:05:04 +08:00
description: "A general guide for using SpaceVim as Perl IDE, including layer configuration, requiems installation and usage."
2020-05-17 14:08:03 +08:00
type: article
2019-02-12 14:18:44 +08:00
comments: true
commentsID: "Use Vim as a Perl IDE"
---
# [Blogs](../blog/) >> Use Vim as a Perl IDE
2019-02-13 23:25:34 +08:00
This is a general guide for using SpaceVim as a Perl IDE, including layer configuration and usage.
2019-02-12 14:18:44 +08:00
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
2019-02-13 23:25:34 +08:00
To add Perl language support in SpaceVim, you need to enable the `lang#perl` layer. Press `SPC f v d` to open
SpaceVim configuration file, and add the following snippet:
2019-02-12 14:18:44 +08:00
```toml
[[layers]]
name = "lang#perl"
```
2019-02-13 23:25:34 +08:00
For more info, you can read the [lang#perl ](../layers/lang/perl/ ) layer documentation.
2019-02-12 14:18:44 +08:00
### Code completion
2019-02-13 23:25:34 +08:00
`lang#perl` layer will load the Perl plugin automatically, unless it's overriden in your `init.toml` .
2019-02-12 14:18:44 +08:00
The completion menu will be opened as you type.
2023-07-05 11:50:23 +08:00
![perlcomplete ](https://img.spacevim.org/52611209-54550500-2ebf-11e9-9b9f-f697a0db52a3.png )
2019-02-12 14:18:44 +08:00
### Syntax linting
The checkers layer is enabled by default. This layer provides asynchronous syntax linting via [neomake ](https://github.com/neomake/neomake ).
2019-02-13 23:25:34 +08:00
It will run Perl and perlcritic asynchronously.
2019-02-12 14:18:44 +08:00
Install perlcritic via cpan:
```sh
cpanm Perl::Critic
```
2023-07-05 11:50:23 +08:00
![perllint ](https://img.spacevim.org/52614908-2cb96900-2ece-11e9-8c73-2881f8030c6e.png )
2019-02-12 14:18:44 +08:00
### Jump to test file
2019-02-13 23:25:34 +08:00
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 the following content:
2019-02-12 14:18:44 +08:00
```json
{
"src/*.pl": {"alternate": "test/{}.pl"},
"test/*.pl": {"alternate": "src/{}.pl"}
}
```
2019-02-13 23:25:34 +08:00
With this configuration, you can jump between the source code and test file via command `:A`
2019-02-12 14:18:44 +08:00
### running code
2019-02-13 23:25:34 +08:00
To run current script, you can press `SPC l r` , and a split window
will be openen, the output of the script will be shown in this window.
It is running asynchronously, and will not block your Vim.
2019-02-12 14:18:44 +08:00
2023-07-05 11:50:23 +08:00
![perlrunner ](https://img.spacevim.org/52611211-54550500-2ebf-11e9-9baf-a6437da8fcf4.png )
2019-02-12 14:18:44 +08:00
### Code formatting
2019-02-13 23:25:34 +08:00
The format layer is also enabled by default. With this layer you can use key binding `SPC b f` to format current buffer.
2019-02-12 14:18:44 +08:00
Before using this feature, please install perltidy:
```sh
cpanm Perl::Tidy
```
### REPL support
2019-02-13 23:25:34 +08:00
Start a `perli` or `perl -del` inferior REPL process with `SPC l s i` . After the REPL process being started, you can
send code to inferior process. All key bindings prefix with `SPC l s` , including sending line, sending selection or even
2019-02-12 14:18:44 +08:00
send whole buffer.
2023-07-05 11:50:23 +08:00
![perlrepl ](https://img.spacevim.org/52611210-54550500-2ebf-11e9-8ba2-b5cd3cc70885.gif )
2019-02-12 14:18:44 +08:00