-
Notifications
You must be signed in to change notification settings - Fork 90
/
splitjoin.txt
2243 lines (1865 loc) · 56.7 KB
/
splitjoin.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*splitjoin.txt* Switch between single-line and multiline forms of code
==============================================================================
CONTENTS *splitjoin* *splitjoin-contents*
Installation...........................: |splitjoin-installation|
Usage..................................: |splitjoin-usage|
C......................................: |splitjoin-c|
Clojure................................: |splitjoin-clojure|
Coffeescript...........................: |splitjoin-coffee|
CSS....................................: |splitjoin-css|
CUE....................................: |splitjoin-cue|
Elixir.................................: |splitjoin-elixir|
Elm....................................: |splitjoin-elm|
Eruby..................................: |splitjoin-eruby|
FASTA..................................: |splitjoin-fasta|
Go.....................................: |splitjoin-go|
HAML...................................: |splitjoin-haml|
HTML...................................: |splitjoin-html|
Handlebars.............................: |splitjoin-handlebars|
Hare...................................: |splitjoin-hare|
Java...................................: |splitjoin-java|
Javascript.............................: |splitjoin-javascript| |splitjoin-json|
JSX/TSX................................: |splitjoin-jsx| |splitjoin-tsx|
Lua....................................: |splitjoin-lua|
Perl...................................: |splitjoin-perl|
PHP....................................: |splitjoin-php|
Python.................................: |splitjoin-python|
R......................................: |splitjoin-r|
Ruby...................................: |splitjoin-ruby|
Rust...................................: |splitjoin-rust|
SCSS/Less..............................: |splitjoin-scss| |splitjoin-less|
Shell..................................: |splitjoin-shell|
TeX....................................: |splitjoin-tex|
Vimscript..............................: |splitjoin-vimscript|
YAML...................................: |splitjoin-yaml|
Settings...............................: |splitjoin-settings|
Internals..............................: |splitjoin-internals|
Issues.................................: |splitjoin-issues|
==============================================================================
INSTALLATION *splitjoin-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:
>
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.
==============================================================================
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 <Leader>j :SplitjoinJoin<cr>
nmap <Leader>s :SplitjoinSplit<cr>
<
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<cr>
nmap sk :SplitjoinJoin<cr>
<
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 <Nop>. 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.
==============================================================================
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);
<
==============================================================================
CLOJURE *splitjoin-clojure*
Lists ~
>
(map (fn [x] (.toUpperCase x)) (.split "one two three" " "))
(map
(fn [x] (.toUpperCase x))
(.split "one two three" " "))
[::namespace/function one two three]
[::namespace/function
one
two
three]
#{:a :b :c :d}
#{:a
:b
:c
:d}
<
==============================================================================
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
'''
<
==============================================================================
CSS *splitjoin-css*
These also work for SCSS and LESS -- see |splitjoin-scss|, |splitjoin-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;
}
<
==============================================================================
CUE *splitjoin-cue*
CUE Structs are JSON objects but with a cleaner syntax. Lists and Function
arguments behave like JSON's.
See |splitjoin-json|.
Structs ~
Structs are first class, so the cursor can precede the first curly brace.
>
a: foo: { x: bar: baz: bool, y: bar: baz: int, z: bar: baz: string }
a: foo: {
x: bar: baz: bool
y: bar: baz: int
z: bar: baz: string
}
<
Lists ~
The same applies to lists.
>
foo: [ 'x:y:z', "\xFFFF0000", a.foo.y ]
foo: [
'x:y:z',
"\xFFFF0000",
a.foo.y
]
<
Function Arguments ~
Function splitting requires the cursor to be positioned inside the
parenthesis, preferably near the closing one.
>
bar: m.Baz(foo[2].bar.baz, 42, true)
bar: m.Baz(
foo[2].bar.baz,
42,
true
)
<
==============================================================================
ELIXIR *splitjoin-elixir*
Do-blocks ~
>
def function(arguments) when condition, do: body
def function(arguments) when condition do
body
end
let :one, do: two() |> three(four())
let :one do
two() |> three(four())
end
if(foo, do: bar, else: baz)
if foo do
bar
else
baz
end
<
Comma-separated method calls (join only): ~
>
for a <- 1..10,
Integer.is_odd(a) do
a
end
for a <- 1..10, Integer.is_odd(a) do
a
end
<
Pipelines: ~
>
String.length("splitjoin")
"splitjoin"
|> String.length()
<
This doesn't currently work properly for multi-line arguments:
>
String.length(
Enum.join([
"split",
"join"
])
)
if true do
"splitjoin"
end
|> String.length()
<
==============================================================================
ELM *splitjoin-elm*
Lists, tuples, records ~
>
myUpdatedRecord =
{myPreviousRecord | firstName = "John", lastName = "Doe"}
myUpdatedRecord =
{ myPreviousRecord
| firstName = "John"
, lastName = "Doe"
}
<
==============================================================================
ERUBY *splitjoin-eruby*
Tags ~
>
<div class="foo">bar</div>
<div class="foo">
bar
</div>
<
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'
} %>
<
==============================================================================
FASTA *splitjoin-fasta*
Sequences ~
>
> E.coli_K12 Cysteine--tRNA ligase
MLKIFNTLTRQKEEFKPIHAGEVGMYVCGITVYDLCHIGHGRTFVAFDVVARYLRFLGYKLKYVRNITDIDDK...
> E.coli_K12 Cysteine--tRNA ligase
MLKIFNTLTRQKEEFKPIHAGEVGMYVCGITVYDLCHIGHGRTFVAFDVVARYLRFLGYK
LKYVRNITDIDDKIIKRANENGESFVAMVDRMIAEMHKDFDALNILRPDMEPRATHHIAE
...
<
==============================================================================
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},
}
<
==============================================================================
HAML *splitjoin-haml*
Evaluated ruby ~
>
%div= 1 + 2
%div
= 1 + 2
<
==============================================================================
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}}
<
==============================================================================
HARE *splitjoin-hare*
Structs ~
>
struct { source: str, line: 1 };
struct {
source: str,
line: 1,
};
<
Function definitions, calls, and arrays ~
>
fn function_def(values: []u8, s: str) void = {};
fn function_def(
values: []u8,
s: str,
) void = {};
function_call(values: []u8, s: str);
function_call(
values: []u8,
s: str,
);
let x = [1, 2, 3];
let x = [
1,
2,
3,
];
<
Question mark operator ~
>
const num = getnumber()?;
const num = match (getnumber()) {
case error => abort();
case let t: type =>
yield t;
};
<
Note that, at the moment, only splitting question marks is supported, joining
an appropriate match expression into a question-mark operator is not.
==============================================================================
HTML *splitjoin-html*
This works for other HTML-like languages as well: XML, Eruby, JSX, TSX, Vue
templates, Svelte.js, Django templates.
Tags ~
>
<div class="foo">bar</div>
<div class="foo">
bar
</div>
<
Attributes ~
>
<button class="foo bar" ng-click="click()" ng-class="{ clicked: clicked }">
Click me!
</button>
<button
class="foo bar"
ng-click="click()"
ng-class="{ clicked: clicked }">
Click me!
</button>
<
==============================================================================
JAVA *splitjoin-java*
If-clause bodies ~
>
if (isTrue())
doSomething();
if (isTrue()) doSomething();
if (isTrue()) {
doSomething();
}
if (isTrue()) { doSomething(); }
<
If-clause conditions ~
>
if (val1 && val2 || val3)
body();
if (val1
&& val2
|| val3)
body();
<
Function calls ~
>
myfunction(arg1, arg2, arg3, arg4);
myfunction(arg1,
arg2,
arg3,
arg4);
<
Lambda functions ~
>
some_function(foo -> "bar");
some_function(foo -> {
return "bar";
});
<
==============================================================================
JAVASCRIPT *splitjoin-javascript*
*splitjoin-json*
Object and Array splitting also work for JSON, if it's set as a separate
filetype. (If it's just set to "javascript", it'll just apply javascript
logic). If the filetype is "json", trailing commas will automatically be
disabled, too.
Objects ~
Just like in ruby and python, the cursor needs to be inside the object in
order to split it.
>
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";
});
<
==============================================================================
JSX *splitjoin-jsx*
*splitjoin-tsx*
Both HTML and Javascript splitters and joiners work for JSX and TSX. There's
also one additional transformation:
Self-closing tags ~
>
let button = <Button />;
let button = <Button>
</Button>;
Note that, in Vim, these languages are supported within the `javascrptreact`
and `typescriptreact` filetypes, so if callbacks don't work right,
double-check the detected filetype of the buffer.
==============================================================================
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
it's assumed this is not 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)
<
==============================================================================
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
as 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
);
<
==============================================================================
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 ~
>
<?php echo "OK"; ?>
<?php
echo "OK";
?>
<
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 (the default
behaviour).
>
$var = $one->two->three()->four();
$var = $one
->two->three()->four();
# OR
$var = $one
->two
->three()
->four();
==============================================================================
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)
<
List comprehensions ~
>
result = [x * y for x in range(1, 10) for y in range(10, 20) if x != y]
result = [x * y
for x in range(1, 10)
for y in range(10, 20)
if x != y]
<
Statements ~
>
if foo: bar()
if foo:
bar()
<
Imports ~
>
from foo import bar, baz