• Stars
    star
    1,918
  • Rank 24,174 (Top 0.5 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 13 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Switch between single-line and multiline forms of code

GitHub version Build Status

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.

Demo

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"
end

The 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 the following languages:

  • C
  • CSS
  • Clojure
  • Coffeescript
  • Elixir
  • Elm
  • Eruby
  • Go
  • HAML
  • HTML (and HTML-like markup)
  • Handlebars
  • Javascript (within JSX, TSX, Vue.js templates as well)
  • JSON
  • Lua
  • PHP
  • Perl
  • Python
  • 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

Installation

The easiest way to install the plugin is with a plugin manager:

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:

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 first.

Issues

Any issues and suggestions are very welcome on the github bugtracker.

More Repositories

1

switch.vim

A simple Vim plugin to switch segments of text with predefined replacements
Ruby
648
star
2

sideways.vim

A Vim plugin to move function arguments (and other delimited-by-something items) left and right.
Ruby
480
star
3

linediff.vim

A vim plugin to perform diffs on blocks of code
Vim Script
463
star
4

tagalong.vim

Change an HTML(ish) opening tag and take the closing one along as well
Vim Script
412
star
5

vimrunner

Control a vim instance through ruby code
Ruby
237
star
6

inline_edit.vim

Edit code that's embedded within other code
Vim Script
150
star
7

typewriter.vim

Make cool typewriter sounds in insert mode
Vim Script
88
star
8

bufferize.vim

Execute a :command and show the output in a temporary buffer
Vim Script
83
star
9

Vimfiles

My .vim folder
Vim Script
79
star
10

deleft.vim

Delete a wrapping if-clause, try-catch block, etc. and shift left.
Vim Script
71
star
11

quickpeek.vim

Show a preview popup on quickfix entries
Vim Script
70
star
12

undoquit.vim

Undo a :quit -- reopen the last window you closed
Ruby
64
star
13

diffurcate.vim

Split a git diff into separate files
Ruby
59
star
14

dsf.vim

Delete surrounding function call
Ruby
52
star
15

id3.vim

"Edit" mp3 files with Vim, or rather, their ID3 tags
Vim Script
51
star
16

ember_tools.vim

Tools for working with ember projects
Vim Script
51
star
17

writable_search.vim

Grep for something, then write the original files directly through the search results.
Vim Script
51
star
18

quickmd

Quickly preview a markdown file
Rust
37
star
19

gnugo.vim

Play a game of Go in your text editor, using GnuGo
Vim Script
33
star
20

discotheque.vim

Emphasize pieces of text, with style.
Vim Script
32
star
21

simple_bookmarks.vim

A small plugin to create named bookmarks in Vim
Vim Script
31
star
22

gapply.vim

Before committing, edit a git diff and apply it directly to the index
Vim Script
28
star
23

whitespaste.vim

Automatically adjust number of blank lines when pasting
Vim Script
26
star
24

image-processing

Some experiments with simple image processing algorithms
Ruby
22
star
25

rails_extra.vim

Some extra tools for working with Rails projects, on top of vim-rails
Vim Script
21
star
26

id3-image

A tool to embed images into mp3 files
Rust
18
star
27

vim-eco

Eco (embedded coffee-script) support for Vim
Vim Script
17
star
28

strftime.vim

Make it easier to read and write strftime strings
Vim Script
16
star
29

exercism.vim

Vim plugin to help out with exercism.io. A thin wrapper around the `exercism` command-line
Vim Script
15
star
30

dealwithit.vim

Show the "deal with it" dog animation in Vim
Vim Script
14
star
31

tagfinder.vim

A simple vim plugin to look for tags of specific kinds: classes, functions, etc.
Vim Script
13
star
32

whatif.vim

What if we could see which if-else branch gets executed? Haha jk... unless?
Ruby
12
star
33

ghundle

A package manager for git hooks
Ruby
11
star
34

yankwin.vim

Yank and paste windows around
Ruby
9
star
35

waiting-on-rails

Bored of waiting on "rails server"? No more!
Ruby
9
star
36

cucumber-vimscript

Cucumber step definitions for testing vimscript
Ruby
9
star
37

scripts

Small scripts to solve minor problems
Ruby
9
star
38

qftools.vim

Tools to manipulate the quickfix window
Vim Script
8
star
39

vim-lectures

Lectures for the Vim course in FMI
Vim Script
8
star
40

id3-json

Read and write ID3 tags with machine-readable input and output
Rust
7
star
41

progressor

Measure iterations in a long-running task
Ruby
7
star
42

popup_scrollbar.vim

A scrollbar for Vim windows built with the popup API
Vim Script
7
star
43

coffee_tools.vim

A work-in-progress plugin with tools for working with coffeescript
Vim Script
7
star
44

dotfiles

My linux configuration files
Shell
6
star
45

awesome-config

My awesome configuration ("awesome" as in the window manager, not as a quality)
Lua
5
star
46

better_netrw.vim

A better file manager for Vim
Vim Script
5
star
47

vim-fmi

The site for the Vim course at Sofia University: https://vim-fmi.bg/
Ruby
5
star
48

dot-shell

My zsh configuration
Shell
5
star
49

xmonad-config

My personal xmonad configuration (not maintained, switched to awesome)
Haskell
5
star
50

andrews_nerdtree.vim

My personal collection of NERDTree extensions
Vim Script
4
star
51

ginitpull.vim

Open a pull request directly from Vim
Vim Script
4
star
52

iseven.vim

Check if a number is even or not
Vim Script
4
star
53

rtranslate.vim

Easier translations with rails
Vim Script
3
star
54

archivitor.vim

Vim plugin for editing the contents of archives
Vim Script
3
star
55

libmarks

A small website to bookmark programming libraries. Inspired by The Ruby Toolbox
Ruby
3
star
56

daily-sites

A website to administer links to regularly visited sites
Ruby
3
star
57

simple_gl

A thin wrapper around ruby's opengl bindings
Ruby
3
star
58

rimplement.vim

Implement a ruby class or method.
Vim Script
2
star
59

rust-shooter

A toy game in Rust
Rust
2
star
60

egui-mp3s

A simple egui demo app
Rust
2
star
61

vim-learning-website

A website that uses the vimgolf gem for vim exercises.
Ruby
2
star
62

modsearch.vim

A command that lets you change the previous search in predefined ways
Ruby
2
star
63

rust-hangman

A simple game of hangman, built for learning purposes
Rust
2
star
64

do-after

A small C program to execute something after a set amount of time.
C
2
star
65

ctags_reader

Read ctags files, provide a ruby interface to get data out of them
Ruby
2
star
66

rust-spotiferris

A Rust web experiment -- a music management app (very incomplete)
Rust
2
star
67

subtitles.vim

(Not working) A vim plugin that helps you with editing subtitles
Vim Script
2
star
68

randfiles

A tool that outputs a list of random files in given directories
Ruby
2
star
69

rustbucket.vim

[WIP] A collection of Rust tools for Vim
Vim Script
2
star
70

gtk4-example

A very basic Rust example of using GTK4
Rust
2
star
71

rust_wrap.vim

Ok-wrap (Some-wrap, Rc-wrap, etc.) Rust functions
Vim Script
2
star
72

bioinformatics-experiments

Sandbox to play around with bioinformatics-related stuff
Python
2
star
73

onchange.vim

Trigger an autocommand upon a code change
Vim Script
2
star
74

digits

Simple experimental project that recognizes a digit in a given BMP image
C++
1
star
75

vsnips.vim

An early stage experiment with snippets
Vim Script
1
star
76

hello-rusty-web

Some example code for a web application in Rust
Rust
1
star
77

rust-bookworm

A toy project that indexes txt-formatted books and allows searching through them
Rust
1
star
78

mount_archive

Mount an archive as a virtual filesystem
Ruby
1
star
79

declarators

Useful method decorators for ruby
Ruby
1
star
80

vim-fmi-cli

The command-line tool for https://vim-fmi.bg
Rust
1
star
81

rust-eliza

A simple chatbot in Rust. Not intended for "serious" use (whatever the serious use for a chatbot might be), just an experiment.
Rust
1
star
82

tdd_workshop

Python
1
star
83

sticky_line.vim

[WIP] Pin lines to the window to always keep them visible while scrolling
Vim Script
1
star
84

protein-runway

Integrated Bioinformatics Project
Python
1
star