splitjoin.vim


Ⅰ. 插件描述

Switch between single-line and multiline forms of code

Ⅱ. 基本信息

创建日期:  2011-03-06
使用用户:  1577
Github星:  1087
插件作者:  Andrew Radev

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'andrewradev/splitjoin-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'andrewradev/splitjoin-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'andrewradev/splitjoin-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/andrewradev/splitjoin.vim

Ⅳ. 文档说明

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
  • Coffeescript
  • Elixir
  • Eruby
  • Go
  • HAML
  • HTML (and HTML-like markup)
  • Handlebars
  • Javascript (within JSX, TSX, Vue.js templates as well)
  • 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.

添加新评论