V 14 12 bytes
#V 14 12 bytes
ThanksThanks @DJMcMayhem for 2 bytes.
Uses a reg-ex to do the substitution. Kind of fun, because it's not a built-in. I have a more fun function, but it's not working the way I expected.
ͨ-©½0]/±1
This just translates to :%s/\v(-)=[^0].*/\11
which matches one or more -
followed by anything but 0, followed by anything any number of times. It's replaced with the first match (so either a -
or nothing) and a 1
. The regex doesn't match 0, so that stays itself.
The More Fun Way (21 bytes)
é
Àé12|DkJòhé-òó^$/a
This accepts the input as an argument rather than in the buffer.
é<CR>
Insert a new line.
À
run the argument as V code. a -
will move the cursor to the previous line, and any number will become the count for the next command
é1
insert (count)1
's
2|
move to the second column
D
delete everything from the second column onwards (leaving only one character)
kJ
Join the two lines together.
òhé-ò
translates to: "run hé-
until breaking". If the 1 was on the second line, this breaks immediately after the h. If it was on the first line, it will insert a -
before breaking.
ó^$/a
This fixes the fact that -1
,0
,1
will leave a blank, and replaces a blank with the argument register.