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
109 lines
3.1 KiB
Markdown
109 lines
3.1 KiB
Markdown
[](https://badge.fury.io/gh/andrewradev%2Fsplitjoin.vim)
|
|
[](https://circleci.com/gh/AndrewRadev/splitjoin.vim?branch=main)
|
|
|
|
## Usage
|
|
|
|
This plugin is meant to simplify a task I've found too common in my workflow: switching between a single-line statement and a multi-line one. It offers the following default keybindings, which can be customized:
|
|
|
|
* `gS` to split a one-liner into multiple lines
|
|
* `gJ` (with the cursor on the first line of a block) to join a block into a single-line statement.
|
|
|
|

|
|
|
|
I usually work with ruby and a lot of expressions can be written very concisely on a single line. A good example is the "if" statement:
|
|
|
|
``` ruby
|
|
puts "foo" if bar?
|
|
```
|
|
|
|
This is a great feature of the language, but when you need to add more statements to the body of the "if", you need to rewrite it:
|
|
|
|
``` ruby
|
|
if bar?
|
|
puts "foo"
|
|
puts "baz"
|
|
end
|
|
```
|
|
|
|
The idea of this plugin is to introduce a single key binding (default: `gS`) for transforming a line like this:
|
|
|
|
``` html
|
|
<div id="foo">bar</div>
|
|
```
|
|
|
|
Into this:
|
|
|
|
``` html
|
|
<div id="foo">
|
|
bar
|
|
</div>
|
|
```
|
|
|
|
And another binding (default: `gJ`) for the opposite transformation.
|
|
|
|
This currently works for various constructs in the following languages:
|
|
|
|
- C
|
|
- CSS
|
|
- Clojure
|
|
- Coffeescript
|
|
- Elixir
|
|
- Elm
|
|
- Eruby
|
|
- Go
|
|
- HAML
|
|
- HTML (and HTML-like markup)
|
|
- Handlebars
|
|
- JSON
|
|
- Java
|
|
- Javascript (within JSX, TSX, Vue.js templates as well)
|
|
- Lua
|
|
- PHP
|
|
- Perl
|
|
- Python
|
|
- R
|
|
- Ruby
|
|
- Rust
|
|
- SCSS and Less
|
|
- Shell (sh, bash, zsh)
|
|
- Tex
|
|
- Vimscript
|
|
- YAML
|
|
|
|
For more information, including examples for all of those languages, try `:help
|
|
splitjoin`, or take a look at the full help file online at
|
|
[doc/splitjoin.txt](https://github.com/AndrewRadev/splitjoin.vim/blob/master/doc/splitjoin.txt)
|
|
|
|
## Installation
|
|
|
|
The easiest way to install the plugin is with a plugin manager:
|
|
|
|
- vim-plug: https://github.com/junegunn/vim-plug
|
|
- Vundle: https://github.com/VundleVim/Vundle.vim
|
|
|
|
If you use one, just follow the instructions in its documentation.
|
|
|
|
You can install the plugin yourself using Vim's "packages" functionality by cloning the project (or adding it as a submodule) under `~/.vim/pack/<any-name>/start/`. For example:
|
|
|
|
```
|
|
git clone https://github.com/AndrewRadev/splitjoin.vim ~/.vim/pack/_/start/splitjoin
|
|
```
|
|
|
|
This should automatically load the plugin for you on Vim start. Alternatively, you can add it to `~/.vim/pack/<any-name>/opt/` instead and load it in your .vimrc manually with:
|
|
|
|
``` vim
|
|
packadd splitjoin
|
|
```
|
|
|
|
If you'd rather not use git, you can download the files from the "releases" tab and unzip them in the relevant directory: https://github.com/AndrewRadev/splitjoin.vim/releases.
|
|
|
|
## Contributing
|
|
|
|
If you'd like to hack on the plugin, please see
|
|
[CONTRIBUTING.md](https://github.com/AndrewRadev/splitjoin.vim/blob/master/CONTRIBUTING.md) first.
|
|
|
|
## Issues
|
|
|
|
Any issues and suggestions are very welcome on the
|
|
[github bugtracker](https://github.com/AndrewRadev/splitjoin.vim/issues).
|