Helix Golf
For all examples, we’ll assume that your cursor is on the very first character
Object into Array
Before
After
Command
mr{[mi[s:<enter>r,t,;vgsms[lems"
mr{[mi[s:<enter>r,t,;vgsms[lems"
- Go inside of the object with
j
mr{[
replaces the surrounding ”{” with ”[”mi[
selects inside the entire array- Use
s
to enter select mode, which searches inside our selection and creates sub-selections based on a pattern - Input
:
and then hitEnter
, which will place a cursor on every ”:” creating many single-width selections r,
replaces each selection with a ”,”. Essentially we’ve replaced each colon with a commat,
moves the cursor on each line to the ending comma;
collapses the selection around each cursor into a single selectionvgs
selects each line excluding the final commams[
surrounds each individual selection with ”[” to turn it into an array. We’re almost done here. We just need to transform the first item in each sub-array into a string.l
moves 1 character forward, replacing the selection with just a 1-width selectione
selects until the end of each word. Since we start at the first character and select until the end, this selects the entire word.ms"
surrounds each word with double quotes to make strings
CSV to SQL
Before
After
Command
%<alt-s>"yys\d<enter>dhhbms``x_ms(IINSERT INTO `database<esc>a.`table<esc>la <esc>AVALUES (<esc>"ypS,ms'A;<esc>Fl;~
%<alt-s>"yys\d<enter>dhhbms``x_ms(IINSERT INTO `database<esc>a.`table<esc>la <esc>AVALUES (<esc>"ypS,ms'A;<esc>Fl;~
-
%
selects full file -
Alt
+s
split selection into multiple selections on newlines -
"yy
yanks the selections into “y” register. We’ll need it for later -
s
and then input the pattern\d
thenEnter
which creates a selection on all digits -
d
deletes the selections. Essentially we’ve removed all the digits. -
hh
goes backwards 2 chars, important to make sure we are at the end of each word -
Use
b
to select till the beginning of every word, which also nicely selects all the words that there are -
ms`
surrounds each word with a backtick -
`
switches all characters to lowercase -
x
selects each line then use_
to trim the trailing whitespace -
ms(
surrounds each line with parentheses -
I
goes into insert mode at the beginning of each line -
Type the following:
-
Escape
goes back to normal mode -
a
to go into insert mode after the backtick then type: -
Escape
goes back into normal mode, thenla
to enter insert mode just before the opening parentheses -
Add a
Space
thenEscape
to go back into normal mode again -
A
goes into insert mode at the end of each line, now type: -
Hit
Escape
to leave insert mode. Your cursor will be at the closing parenthesis. -
"yp
pastes our previously yanked items from the “y” register -
S,
splits current selection into multiple selections on each comma -
ms'
surrounds each item with a single quote -
A;
adds a semicolon at the end of each line -
Escape
goes back to normal mode andFl
to place your cursor on the lowercase “l” of each “location” -
;
collapses each selection into a single-width selection -
~
toggles the case for each “l” into “L”
Convert functions into a class
Before
After
Command
%scalculate<enter>cget<esc>O@staticmethod<esc>jxxs\w+<enter>slength|width|height<enter>bllled%sresult =<enter>C<alt-(>;ddss<enter>xd%>O<backspace>class Calculator:
%scalculate<enter>cget<esc>O@staticmethod<esc>jxxs\w+<enter>slength|width|height<enter>bllled%sresult =<enter>C<alt-(>;ddss<enter>xd%>O<backspace>class Calculator:
-
%
selects the entire file -
s
searches inside the current selection and creates sub-selections based on a pattern. Inputcalculate
then hitEnter
to make a selection on all instances of the word -
c
then typeget
to change each “calculate” word into a “get” -
Escape
to go back to normal mode -
Use
O
to create an empty line above each cursor, write: -
Hit
Esc
to go into normal mode. -
We need to select 2 lines below the current line, first go down with
j
and then pressxx
which will select the current line, and then select the next line In total we now have 3 cursors each with 2 lines selected, which includes the first line of the bodies of each function and the function definition themselves -
s
brings up a prompt to select sub-selections by a given regex. The\w+
regex selects each word, type it and thenEnter
-
s
again then typelength|width|height
followed byEnter
. This will look at the contents of the current selections, and create sub-selections where it finds the regex which means “length or width or height”. So we select each instance of those 3 words -
Our cursor is currently at the end of each word. Let’s go to the beginning with
b
-
We want to keep the first 3 characters and discard the rest from each of the parameters. To do this, move to the 4th character with
lll
-
Use
e
to select until the end of each word and thend
to delete it -
Select the entire file again with
%
followed bys
to bring up selection prompt again -
Write
result =
followed byEnter
to select all instances of that string -
C
creates a new selection on the line directly below, for each cursor -
Use
Alt
+(
to rotate the contents of the selection backward -
;
collapses each cursor into a single selection -
dd
deletes two characters on each of the 6 lines -
s
to bring up the prompt, then inputs
followed byEnter
to select all “s” characters -
Select each of the lines with
x
followed byd
to delete -
Select whole file with
%
and indent with>
-
O
creates a newline above and enters Insert mode, thenBackspace
to delete an extra tab -
Write this: