Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
1560 lines (1285 sloc) 38.9 KB
 *splitjoin.txt* Switch between single-line and multiline forms of code ============================================================================== CONTENTS *splitjoin* *splitjoin-contents* Installation...........................: |splitjoin-installation| Usage..................................: |splitjoin-usage| Ruby...................................: |splitjoin-ruby| Python.................................: |splitjoin-python| Perl...................................: |splitjoin-perl| Coffeescript...........................: |splitjoin-coffee| Lua....................................: |splitjoin-lua| Javascript.............................: |splitjoin-javascript| Rust...................................: |splitjoin-rust| PHP....................................: |splitjoin-php| Vimscript..............................: |splitjoin-vimscript| HTML...................................: |splitjoin-html| Handlebars.............................: |splitjoin-handlebars| CSS....................................: |splitjoin-css| YAML...................................: |splitjoin-yaml| Eruby..................................: |splitjoin-eruby| Go.....................................: |splitjoin-go| TeX....................................: |splitjoin-tex| C......................................: |splitjoin-c| Elixir.................................: |splitjoin-elixir| Settings...............................: |splitjoin-settings| Internals..............................: |splitjoin-internals| Issues.................................: |splitjoin-issues| ============================================================================== INSTALLATION *splitjoin-installation* There are several ways to install the plugin. The recommended one is by using Tim Pope's pathogen (http://www.vim.org/scripts/script.php?script_id=2332). In that case, you can clone the plugin's git repository like so: > git clone git://github.com/AndrewRadev/splitjoin.vim.git ~/.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 git://github.com/AndrewRadev/splitjoin.vim.git bundle/splitjoin < Another way is to simply copy all the essential directories inside the ~/.vim directory: plugin, ftplugin, autoload, doc. ============================================================================== USAGE *splitjoin-usage* *:SplitjoinSplit* *:SplitjoinJoin* After the plugin is installed, the mapping gS will perform splitting and |gJ| -- joining of the code under the cursor. These mappings are configurable with |g:splitjoin_split_mapping| and |g:splitjoin_join_mapping|, respectively. You could also use the commands |:SplitjoinSplit| and |:SplitjoinJoin|, either directly, or in your own scripts. Note that |gJ| is a built-in mapping that is used for joining lines while preserving whitespace. However, if no splitting/joining is possible at this point, the plugin will fall back to the default mapping. If you'd rather have the splitjoin mappings be no-ops in that case, you could set the mapping variables to empty strings, which will simply not create them at all. You can then make your own simple mappings by using the commands: > let g:splitjoin_split_mapping = '' let g:splitjoin_join_mapping = '' nmap j :SplitjoinJoin nmap s :SplitjoinSplit < For the record, my personal preference is to avoid mnemonics in this case and go for an approach that makes more sense to my fingers instead: > nmap sj :SplitjoinSplit nmap sk :SplitjoinJoin < Notice that I'm using "sj" for splitting, not joining. To me, "splitting" a line results in expanding it downwards, so using "j" seems more intuitive, likewise for "k". The "s" key is ordinarily taken (try :help s), but I don't use it, so I've mapped it to . Your mileage may vary. Splitting ~ Splitting a line consists of checking for blocks of text that the plugin knows how to split and, well, doing that. For example, if we have a ruby hash: > { :one => 'two', :three => 'four' } < Then, with the cursor within the hash, we can split it to get: > { :one => 'two', :three => 'four' } < This works for various other things, you can see some examples for each filetype below. If there are several different kinds of splittings that can be executed, there is a fixed priority. For instance, this: > { :one => 'two', :three => 'four' } if foo? < will be split into this: > if foo? { :one => 'two', :three => 'four' } end < In this case, the plugin does not take into account where exactly the cursor is located on the line, it just always gives priority to the if clause. For ruby hashes in particular, the cursor position is considered, however. Let's take this as an example: > foo 1, 2, { :bar => :baz }, { :baz => :qux } < If the cursor is located on the first hash, the result will be: > foo 1, 2, { :bar => :baz }, { :baz => :qux } < If it's on the second hash, or on any other part of the method call (like on "foo"), you'll get this: > foo 1, 2, { :bar => :baz }, { :baz => :qux } < In general, if you're trying to split a structure, try to "be inside" when you do so. This doesn't make sense in cases like the "if" statement, but it does for hashes. Joining ~ Joining might impose more constraints. Take this as an example: > if foo? bar end < In order to turn this into: > bar if foo? < you need to place your cursor on the line with the "if" clause. If your cursor is on the "bar" line, joining will not work. This might be considered a bug (I find it simpler cognitively to join blocks when I'm within them), but it simplifies the implementation and solves some ambiguity. This might be a nice example: > if foo? { :one => :two, :three => :four } end < Joining when on the line ":one => :two" would currently do nothing. However, if we wanted to detect the type of joining we could do, we might give priority to the if clause instead of the hash, which would not make a lot of sense. Of course, with smart prioritization (or a change in implementation), it might be possible to get things working sensibly, but this seems to be good enough for now: To join the hash, be on the "{" line, to join the "if" clause (not a good idea, mind you, doesn't do anything that makes sense), be on the "if foo?" line. The basic rule of thumb here is that, to join a structure, the cursor should usually be at its beginning (the opening tag, the opening brace, etc.). Settings ~ The plugin has many settings that implement different coding styles. It can be made to align dictionary items, leave or remove trailing commas, and so on. See |splitjoin-settings| for the full list. Note that all of the settings apart from mapping ones can be set as both global variables, and buffer-local ones. So, for instance, you could set |g:splitjoin_align| to 0 in order to avoid aligning code in most cases, but set |b:splitjoin_align| to 1 in your ~/.vim/ftplugin/ruby.vim file to align ruby code in particular. The buffer-local variables will take precedence. Now for some examples for the filetypes that have splitjoin implementations. ============================================================================== RUBY *splitjoin-ruby* If/unless/while/until clauses ~ Joining works for more-than-one-line "if" clauses as well, but it doesn't look very pretty. It's generally recommended to use it only when the body is a single line. > return "the answer" if 6 * 9 == 42 if 6 * 9 == 42 return "the answer" end < Hashes ~ To split a hash, you need to be within the curly brackets. Otherwise, the plugin attempts to split it as a block. > foo = { :bar => 'baz', :one => 'two' } foo = { :bar => 'baz', :one => 'two' } < Option hashes ~ There's an option, |splitjoin_ruby_curly_braces|, that controls whether the curly braces are present after splitting or joining. > foo 1, 2, :one => 1, :two => 2 foo 1, 2, { :one => 1, :two => 2 } # note that after joining, the result will be: foo 1, 2, { :one => 1, :two => 2 } < Method arguments ~ These only get split if there is no option hash at the end. The variable |splitjoin_ruby_hanging_args| controls whether the arguments will be left "hanging", aligned near the brackets, or if the brackets will be put on their own lines. Joining for the "hanging" style doesn't really work, since there's no easy, reliable way to detect the continued arguments. However, a simple vanilla-vim J should do the trick. > params.permit(:title, :action, :subject_type, :subject_id, :own) params.permit(:title, :action, :subject_type, :subject_id, :own) # with splitjoin_ruby_hanging_args == 0 params.permit( :title, :action, :subject_type, :subject_id, :own ) < Caching constructs ~ > @two ||= 1 + 1 @two ||= begin 1 + 1 end < Blocks ~ > Bar.new { |b| puts b.to_s } Bar.new do |b| puts b.to_s end < Block &-shorthand ~ > [1, 2, 3].map(&:to_s) [1, 2, 3].map do |i| i.to_s end < Heredocs ~ > string = 'something' string = <<-EOF something EOF < Ternaries ~ > if condition do_foo else do_bar end condition ? do_foo : do_bar < Cases ~ Splits or joins single when clauses, if the cursors sits on the line of such a when, or the whole case, if you have or cursor in the line of the case-keyword, as shown in the example. > case condition when :a do_foo when :b do_bar else do_baz end case condition when :a then do_foo when :b then do_bar else do_baz end > Arrays ~ > list = ['one', 'two', 'three'] list = [ 'one', 'two', 'three' ] < Array literals ~ > list = %w{one two three} list = %w{ one two three } < Module namespacing ~ Note that splitting and joining module namespaces relies on the built-in |matchit| plugin being loaded. Check |matchit-install| for details. > module Foo class Bar < Baz def qux end end end class Foo::Bar < Baz def qux end end < ============================================================================== PYTHON *splitjoin-python* Just like in ruby, the cursor needs to be inside the dict in order to split it correctly, otherwise it tries to split it as a statement (which works, due to the dict having ":" characters in it). Dicts ~ > knights = {'gallahad': 'the pure', 'robin': 'the brave'} knights = { 'gallahad': 'the pure', 'robin': 'the brave' } < Lists ~ > spam = [1, 2, 3] spam = [1, 2, 3] < Tuples ~ > spam = (1, 2, 3) spam = (1, 2, 3) < Statements ~ > if foo: bar() if foo: bar() < Imports ~ > from foo import bar, baz from foo import bar,\ baz < Assignment ~ > a, b = foo("bar"), [one, two, three] a = foo("bar") b = [one, two, three] un, pack = something un = something[0] pack = something[1] < Note that splitting a, b = b, a would not result in an expression that works the same way, due to the special handling by python of this case to swap two values. ============================================================================== PERL *splitjoin-perl* If/unless/while/until clauses ~ The variable |splitjoin_perl_brace_on_same_line| controls the format of the curly braces when joining. If it's set to 0, the opening curly brace will be on its own line. Otherwise, it'll be placed on the same line as the if-clause (the default behaviour). > print "a = $a\n" if$debug; if ($debug) { print "a =$a\n"; } < And/or clauses ~ It only makes sense to split these -- joining results in joining an if/unless clause. The variable |splitjoin_perl_brace_on_same_line| affects the results just like explained above. > open PID, ">", $pidfile or die; unless (open PID, ">",$pidfile) { die; } < Hashes ~ > my $info = {name =>$name, age => $age}; my$info = { name => $name, age =>$age, }; < Lists ~ > my @var = ['one', 'two', 'three']; my @var = [ 'one', 'two', 'three' ]; my @var = ('one', 'two', 'three'); my @var = ( 'one', 'two', 'three' ); < Word lists ~ > my @var = qw(one two three); my @var = qw( one two three ); < ============================================================================== COFFEESCRIPT *splitjoin-coffee* Functions ~ > (foo, bar) -> console.log foo (foo, bar) -> console.log foo < If/unless/while/until clauses ~ Since it's possible to join a multiline if into either a postfix or suffix variant, a variable controls which one it'll be, |splitjoin_coffee_suffix_if_clause|. By default, it's 1, which joins into the suffix format. > console.log bar if foo? if foo? then console.log bar if foo? console.log bar < Ternary operator ~ Splitting takes into account the entire line. If the line starts with assignment, it tries to squeeze in the assignment part on both lines. Joining attempts to do the same process in reverse -- if the same variable is being assigned to different things in both cases, that variable is moved out in front of the if-clause. Otherwise, it just joins the if-then-else without any magic. > foo = if bar? then 'baz' else 'qux' if bar? foo = 'baz' else foo = 'qux' foo = if bar? then 'baz' else 'qux' < Object literals ~ > one = { one: "two", three: "four" } one = one: "two" three: "four" < Object literals in function calls ~ Only splitting works this way for now, the reverse direction falls back to the normal object literal joining. > foo = functionCall(one, two, three: four, five: six) foo = functionCall one, two, three: four five: six < Multiline strings ~ Note that strings are split only at the end of the line. This seems to be the most common case, and the restriction avoids conflicts with other kinds of splitting. > foo = "example with #{interpolation} and \"nested\" quotes" foo = """ example with #{interpolation} and "nested" quotes """ bar = 'example with single quotes' bar = ''' example with single quotes ''' < ============================================================================== LUA *splitjoin-lua* For lua, only splitting and joining functions is implemented at this point. Note that joining a function attempts to connect the lines of the body by using ";". This doesn't always work -- a few constructs are not syntactically valid if joined in this way. Still, the idea is to inline small functions, so this shouldn't be a big issue. Functions ~ > function example () print("foo") print("bar") end function example () print("foo"); print("bar") end local something = other(function (one, two) print("foo") end) local something = other(function (one, two) print("foo") end) < ============================================================================== JAVASCRIPT *splitjoin-javascript* Objects ~ Just like in ruby and python, the cursor needs to be inside the object in order to split it. This and the array splitting also work for JSON, if it's set as a separate filetype. (If it's just set to "javascript", it'll work fine as well). > var one = {one: "two", three: "four"}; var one = { one: "two", three: "four" }; < Arrays ~ > var one = ['two', 'three', 'four']; var one = [ 'two', 'three', 'four' ]; Function Arguments ~ > var foo = bar('one', 'two', 'three'); var foo = bar( 'one', 'two', 'three' ); < Functions ~ When the cursor is on the "function" keyword, the script attempts to split the curly braces of the function. This is a bit more convenient for the common use-case of one-line to multi-line functions. > var callback = function (something, other) { something_else; }; var callback = function (something, other) { something_else; }; < One-line if conditionals ~ > if (isTrue()) { doSomething(); } if (isTrue()) doSomething; < Fat-arrow functions ~ > some_function(foo => "bar"); some_function(foo => { return "bar"; }); < ============================================================================== RUST *splitjoin-rust* Structs ~ > Scanner { source: String::new(), line: 1 } Scanner { source: String::new(), line: 1 } < Match clauses ~ > match one { Ok(two) => some_expression(three), } match one { Ok(two) => { some_expression(three) }, } < Question mark operator ~ > let file = File::open("foo.txt")?; let file = match File::open("foo.txt") { Ok(value) => value, Err(e) => return Err(e.into()), }; let thing = Some(3)?; let thing = match Some(3) { None => return None, Some(value) => value, }; < Note that the plugin determines how to split a ? by looking upwards for a -> Result or -> Option . If it can't find anything, it'll default to a Result. Fallback match split ~ > let foo = Some::value(chain).of(things); let foo = match Some::value(chain).of(things) { } < This one only splits, and is attempted last. The cursor MUST be on Some in order to get this effect, in this particular example. The plugin attempts to find the end of the expression, and make a match statement out of it. This is, at this time, experimental, because I've found myself trying to do it. It might be made smarter, or it might be dropped, so be warned. ============================================================================== PHP *splitjoin-php* Arrays ~ > foo = array('one' => 'two', 'two' => 'three') foo = array( 'one' => 'two', 'two' => 'three' ) < Short arrays ~ > $one = ['two', 'three', 'four']$one = [ 'two', 'three', 'four' ] < If-clauses ~ > if ($foo) {$a = "bar"; } if ($foo) {$a = "bar"; } < PHP markers ~ > < Method calls~ Affects all the arrows after the cursor when |splitjoin_php_method_chain_full| is set to 1. Otherwise, it affects only a single arrow. > $var =$one->two->three()->four(); $var =$one ->two->three()->four(); # OR $var =$one ->two ->three() ->four(); ============================================================================== VIMSCRIPT *splitjoin-vimscript* Vimscript can generally be split anywhere by simply placing the remainder of the line on the next one, prefixed by a backslash. That's why joining is fairly easy to do for the most general case -- anything that is followed by a line, starting with a backslash, can be joined with the current one. > let example_one = { \ 'one': 'two', \ 'three': 'four' \ } " is joined into: let example_one = { 'one': 'two', 'three': 'four' } command! Foo if one | \ 'two' | \ else | \ 'three' | \ endif " is joined into: command! Foo if one | 'two' | else | 'three' | endif < Splitting is a bit trickier, since anything can be split at any point. While it's possible to handle some specific cases like dictionaries, arrays, and commands, for now the plugin takes the simple approach of splitting precisely where the cursor is right now. In the future, this may be replaced with specific splits based on the context. ============================================================================== HTML *splitjoin-html* Tags ~ >
bar
bar
< Attributes ~ > < ============================================================================== HANDLEBARS *splitjoin-handlebars* Components ~ > {{some/component-name foo=bar bar=baz}} {{some/component-name foo=bar bar=baz }} < Block components ~ > {{#component-name foo=bar}}Some content{{/component-name}} {{#component-name foo=bar}} Some contents {{/component-name}} < ============================================================================== CSS *splitjoin-css* These also work for SCSS and LESS. Style definitions ~ > a { color: #0000FF; text-decoration: underline; } a { color: #0000FF; text-decoration: underline; } Multiline selectors ~ > h1, h2, h3 { font-size: 18px; font-weight: bold; } h1, h2, h3 { font-size: 18px; font-weight: bold; } < ============================================================================== YAML *splitjoin-yaml* Arrays ~ > root: one: [1, 2] two: ['three', 'four'] root: one: - 1 - 2 two: - 'three' - 'four' < Maps ~ > root: one: { foo: bar } two: { three: ['four', 'five'], six: seven } root: one: foo: bar two: three: ['four', 'five'] six: seven < ============================================================================== ERUBY *splitjoin-eruby* Tags ~ >
bar
bar
< If/unless clauses ~ > <%= foo if bar? %> <% if bar? %> <%= foo %> <% end %> < Hashes ~ > <% foo = { :bar => 'baz', :one => :two, :five => 'six' } %> <% foo = { :bar => 'baz', :one => :two, :five => 'six' } %> < Option hashes ~ > <%= link_to 'Google', 'http://google.com', :class => 'google', :id => 'google-link' %> <%= link_to 'Google', 'http://google.com', { :class => 'google', :id => 'google-link' } %> < ============================================================================== GO *splitjoin-go* Imports ~ > import "fmt" import ( "fmt" ) < Var/const ~ > var foo string var ( foo string ) < Structs ~ > StructType{one: 1, two: "asdf", three: []int{1, 2, 3}} StructType{ one: 1, two: "asdf", three: []int{1, 2, 3}, } < ============================================================================== TEX *splitjoin-tex* Begin-end blocks ~ > \begin{align*} x = y\\ y = z \end{align*} \begin{align*} x = y\\ y = z \end{align*} < Enumerations ~ > \begin{enumerate} \item item1 \item item2 \end{enumerate} \begin{enumerate} \item item1 \item item2 \end{enumerate} < ============================================================================== C *splitjoin-c* If clauses ~ > if (val1 && val2 || val3); if (val1 && val2 || val3); < Function calls ~ > myfunction(arg1, arg2, arg3, arg4); myfunction(arg1, arg2, arg3, arg4); < ============================================================================== ELIXIR *splitjoin-elixir* Do-blocks ~ > def function(arguments) when condition, do: body def function(arguments) when condition do body end < ============================================================================== SETTINGS *splitjoin-settings* These are the variables that control the behaviour of the plugin. *b:splitjoin_split_callbacks* *b:splitjoin_join_callbacks* > b:splitjoin_split_callbacks b:splitjoin_join_callbacks < Default value: depends on the filetype These two variables contain lists of functions that are called to execute the splitting or joining functionality. If they are set to an empty array in a particular file, this will effectively disable the plugin for it. Example: Putting the following in ftplugin/ruby.vim will disable the join functionality for ruby files: > let b:splitjoin_join_callbacks = [] < *g:splitjoin_split_mapping* *g:splitjoin_join_mapping* > let g:splitjoin_split_mapping = 'cS' let g:splitjoin_join_mapping = 'cJ' < Default values: 'gS' and 'gJ' Changing these values changes the default mappings of the plugin. Note that, if no splitting or joining can be performed, these default mappings will fall back to performing the key sequence's built-in functionality. Set to a blank string to disable default mappings completely. You can still create your own mapping the old-fashioned way using the |:SplitjoinSplit| and |:SplitjoinJoin| commands, though in the case with no possible splitting/joining, nothing will happen. *splitjoin_normalize_whitespace* > g:splitjoin_normalize_whitespace < Default value: 1 This variable controls whether duplicate whitespace should be reduced within a joined structure, which makes a lot of sense in most situations, particularly when the items are aligned. Set it to 0 to disable this behaviour. Example: When this setting is enabled, the extra whitespace around "=>" symbols in ruby hashes is removed: > one = { :one => 'two', :three => 'four', :a => 'b' } one = { :one => 'two', :three => 'four', :a => 'b' } < *splitjoin_align* *g:splitjoin_align* *b:splitjoin_align* > g:splitjoin_align b:splitjoin_align < Default value: 0 This is a flag that controls whether a few constructs should be aligned by a certain character. As a specific example, when you split ruby hashes, this can align them by the "=>" signs. In a way, |splitjoin_normalize_whitespace| is a complement to this setting, since you'd probably want to reduce the extra whitespace when joining. Set the flag to 1 to attempt alignment. In order for it to work, it requires that you have either Tabular (https://github.com/godlygeek/tabular) or Align (http://www.vim.org/scripts/script.php?script_id=294) installed. If that's not the case, the value of this setting will be ignored. Example: > one = { :one => 'two', :three => 'four', :a => 'b' } one = { :one => 'two', :three => 'four', :a => 'b' } < *splitjoin_curly_brace_padding* > g:splitjoin_curly_brace_padding b:splitjoin_curly_brace_padding < Default value: 1 Controls whether joining things with curly braces will add a space between the brackets and the joined body. So, setting it to 0 or 1 results in, respectively: > import {one, two, three} from 'foo'; import { one, two, three } from 'foo'; < *splitjoin_trailing_comma* > g:splitjoin_trailing_comma b:splitjoin_trailing_comma < Default value: 0 This adds a trailing comma when splitting lists of things. There is a ruby-specific setting called |splitjoin_ruby_trailing_comma|, but it's preferred to use this one. You can easily set it per-filetype by using the buffer-local variable with the same name. Example: > one = { :one => 'two', :a => 'b' } one = { :one => 'two', :a => 'b', } < *splitjoin_ruby_curly_braces* > g:splitjoin_ruby_curly_braces < Default value: 1 This flag controls the formatting of ruby option hashes when splitting. When it's 1, curly braces will be present in option blocks. Example: > User.new :one, :first_name => "Andrew", :last_name => "Radev" User.new :one, { :first_name => "Andrew", :last_name => "Radev" } < When the flag is 0, the result will be: > User.new :one, :first_name => "Andrew", :last_name => "Radev" < This won't always have effect. In some cases, it's not syntactically valid to omit the curly braces, which is part of the reason I prefer having them around. However, when there's a non-optional argument or the option hashes is wrapped in round braces, it should work just fine. Regardless of the value of this option, the second example will be joined back to: > User.new :one, :first_name => "Andrew", :last_name => "Radev" < That's because it's easy to infer that it's an option block. Unfortunately, it's more difficult to decide whether we have an option block or a plain hash if there are braces, so the first example will always be joined to: > User.new :one, { :first_name => "Andrew", :last_name => "Radev" } < *splitjoin_ruby_trailing_comma* > g:splitjoin_ruby_trailing_comma < Default value: 0 This controls whether to put a trailing comma on a split hash. With this set to 1, a hash will split like so: > User.new :one, :first_name => "Andrew", :last_name => "Radev" User.new :one, { :first_name => "Andrew", :last_name => "Radev", } < Note the trailing comma for the last element. *splitjoin_ruby_hanging_args* > g:splitjoin_ruby_hanging_args < Default value: 1 This controls whether to split function arguments in the "hanging" style: > params.permit(:title, :action, :subject) < If it is set to 0, the result will be: > params.permit( :title, :action, :subject ) < *splitjoin_ruby_do_block_split* > g:splitjoin_ruby_do_block_split < Default value: 1 This controls whether to convert split blocks to their do-form. It's set to "1" by default, so block split like so: > [1, 2, 3].map { |n| n ** 2 } [1, 2, 3].map do |n| n ** 2 end < If it is set to 0, the result will be: > [1, 2, 3].map { |n| n ** 2 } [1, 2, 3].map { |n| n ** 2 } < *splitjoin_coffee_suffix_if_clause* > g:splitjoin_coffee_suffix_if_clause < Default value: 1 This flag controls the kind of if-clause to use when joining multiline if-clauses in coffeescript. Given the following example: > if foo? console.log bar < Joining this construct with |splitjoin_coffee_suffix_if_clause| set to 1 (the default) would produce: > console.log bar if foo? < Doing that with |splitjoin_coffee_suffix_if_clause| set to 0 would result in: > if foo? then console.log bar < *splitjoin_perl_brace_on_same_line* > g:splitjoin_perl_brace_on_same_line < Default value: 1 This flag controls the placement of curly braces when joining if-clauses. When it's 1 (the default), the opening brace will be placed on the same line: > if ($debug) { print "a =$a\n"; } < If it's set to 0, the brace will get its own line: > if ($debug) { print "a =$a\n"; } < *splitjoin_ruby_heredoc_type* > g:splitjoin_ruby_heredoc_type < Default value: "<<-" This setting can be one of "<<-" and "<<" and controls how strings will be split into heredocs. If it's "<<-", the following form is used > do foo = <<-EOF something EOF end < If it's set to "<<", the result is this: > do foo = < g:splitjoin_python_brackets_on_separate_lines < Default value: 0 If set to 1, then python will split lists and tuples so that the opening and closing bracket are placed on separate lines. If it's 0, the first argument will remain where it is, and the rest will be split on separate lines. Example: > # let g:splitjoin_python_brackets_on_separate_lines = 1 some_method( one, two ) # let g:splitjoin_python_brackets_on_separate_lines = 0 some_method(one, two) < The first example might look a bit odd, but if you have the python-pep8-indent plugin (https://github.com/hynek/vim-python-pep8-indent), it should look quite reasonable. *splitjoin_handlebars_closing_bracket_on_same_line* > g:splitjoin_handlebars_closing_bracket_on_same_line < Default value: 0 If set to 1, then handlebars will keep the closing "}}" on the same line as the last line of the component. At the time of writing, this isn't indented very well, but it might be improved in the future. If it's 0, the closing "}}" will be placed on its own line. handlebars_hanging_arguments *splitjoin_handlebars_hanging_arguments* > g:splitjoin_handlebars_hanging_arguments < Default value: 0 If set to 1, then handlebars will keep one argument on the first line when splitting, so the component will look "hanging". With the closing bracket on the same line, as above, and the right indentation (my own fork of mustache-handlebars, for example: https://github.com/AndrewRadev/vim-mustache-handlebars), it might look like this: > {{foo-bar one="two" three="four"}} < If it's 0, the default, all parameters will be on their own line: > {{foo-bar one="two" three="four"}} < *splitjoin_html_attributes_bracket_on_new_line* > g:splitjoin_html_attributes_bracket_on_new_line < Default value: 0 If set to 1, then splitting HTML attributes will put the closing angle bracket on a new line on its own, like this: >
text
< When set to 0, as is the default, it will look like this: >
text
< *splitjoin_html_attributes_hanging* > g:splitjoin_html_attributes_hanging < Default value: 0 If set to 1, then splitting HTML attributes will keep the first attribute on the same line, and split the rest. Combined with indentation support, it should look like this: > < When set to 0, as is the default, it will look like this: > < *splitjoin_php_method_chain_full* > g:splitjoin_php_method_chain_full < Default value: 0 If set to 1, then splitting a method chain will split all the arrows after the cursor. > $var =$foo->one()->two()->three(); Splitting on "->two" if set to 0: > $var =$foo->one() ->two()->three(); If set to 1: > $var =$foo->one() ->two() ->three(); Joining a chain will also join all the methods calls. ============================================================================== INTERNALS *splitjoin-internals* The only interface of the plugin is in 'plugin/splitjoin.vim'. It's a fairly short file containing two commands, |:SplitjoinSplit| and |:SplitjoinJoin|. All of the actual splitting and joining logic is in autoloaded files. The only things that these two commands do are: - Check the |b:splitjoin_join_callbacks| and |b:splitjoin_split_callbacks| respectively for a list of function names. - Invoke the functions, in order. If any of the functions returns a number different than 0, stop. The actual functions may do whatever they want, but it makes sense for them to return 0 only if they haven't made any modifications to the buffer. The function names could be buffer-local, global, autoloaded, anything the |function()| call can use. Obviously, extending the plugin is straightforward -- it's enough to define a function for splitting and one for joining and add those to the buffer variable. Of course, that doesn't imply it's easy -- the functions would need to actually perform all the necessary manipulations and simply inform the plugin if they've been successful by returning a number other than 0 as a result. The file 'autoload/sj.vim' contains helpers that might be useful for said manipulations. There are functions for replacing bodies of text defined by normal mode motions or by line ranges, for saving and restoring the cursor position and possibly other interesting functions that might assist. They should be commented reasonably well. The other files in 'autoload/sj' might be useful as well, although they're mostly filetype-specific. The files in 'autoload/sj/argparser' contain small parsers for parts of a few of the languages that are supported. They're necessary for splitting dictionary objects, since those can have a lot of structure and usually can't be analyzed properly with just regular expressions. ============================================================================== ISSUES *splitjoin-issues* - Currently, splitting ruby hashes breaks when dealing with multibyte characters, like japanese, joining the final line with the one below it. - If |g:splitjoin_align| is truthy and the Align plugin is being used, the "undo" action undoes only the alignment first, then the splitting. - Joining ruby option hashes could result in a pair of unnecessary curly braces. Any other issues and suggestions are very welcome on the github bugtracker: https://github.com/AndrewRadev/splitjoin.vim/issues vim:tw=78:sw=4:ft=help:norl: