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:
gSto split a one-liner into multiple linesgJ(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:
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:
if bar?
puts "foo"
puts "baz"
endThe idea of this plugin is to introduce a single key binding (default: gS) for transforming a
line like this:
<div id="foo">bar</div>Into this:
<div id="foo">
bar
</div>And another binding (default: gJ) for the opposite transformation.
This currently works for:
- Various constructs in Ruby and Eruby
- Various constructs in Coffeescript
- Various constructs in Perl
- Various constructs in Python
- Various constructs in Rust
- PHP arrays
- Javascript object literals and functions
- Tags in HTML/XML
- Handlebars components
- CSS, SCSS, LESS style declarations.
- YAML arrays and maps
- Lua functions and tables
- Go structs
- Vimscript line continuations
- TeX blocks
- C if clauses and function calls
- Do-blocks in Elixir
For more information, including examples for all of those languages, try :help splitjoin, or take a look at the help file online at
doc/splitjoin.txt
There are several ways to install the plugin. The recommended one is by using Tim Pope's pathogen. In that case, you can clone the plugin's git repository like so:
git clone https://github.com/AndrewRadev/splitjoin.vim ~/.vim/bundle/splitjoin
If your vim configuration is under git version control, you could also set up the repository as a submodule, which would allow you to update more easily. The command is (provided you're in ~/.vim):
git submodule add https://github.com/AndrewRadev/splitjoin.vim bundle/splitjoin
Another way is to simply copy all the essential directories inside the ~/.vim directory: plugin, ftplugin, autoload, doc.
If you'd like to hack on the plugin, please see CONTRIBUTING.md first.
Any issues and suggestions are very welcome on the github bugtracker.

