9
1
Your task is to build a vim script or provide a sequence of keystrokes that will operate on a single line of text with up to 140 printable ASCII characters (anywhere in a file, with the cursor starting anywhere in the line) and reverse every space-separated string in the sentence while keeping the strings in the same order.
For example, the input:
roF emos nosaer m'I gnisu a retcarahc-041 timil no siht noitseuq neve hguoht ti t'nseod evlovni .rettiwT RACECAR
should return:
For some reason I'm using a 140-character limit on this question even though it doesn't involve Twitter. RACECAR
The script with the fewest characters, or the sequence of the fewest keystrokes, to achieve this result is the winner.
Can the cursor be anywhere on the line or can we assume it's at the start? (Or somewhere else?) Will this be just one line in a larger text file or the only contents of the file? Will it be only printable ASCII or could the be tabs, say? If so, to tabs delimit words or not? Also, does this have to be limited to vim? Wouldn't the challenge make just as much sense in emacs or some other scriptable editor? – Martin Ender – 2015-03-28T18:05:34.833
The cursor can be anywhere on the line. This will be a single line in a larger text file. Only printable ASCII characters will appear on the line. For the purposes of this question it's vim only, but feel free to post the Emacs equivalent. – Joe Z. – 2015-03-28T18:06:49.273
1
"For the purposes of this question it's vim only" seems as arbitrary a language-restriction as posting a normal code golf challenge and asking only for answers in C. (And I don't seem to be alone with this opinion.)
– Martin Ender – 2015-03-28T18:08:47.580I admit that it seems that way, but I haven't seen anybody else post editor-agnostic puzzles, and vim-golf is generally a much larger community than, say, emacs-golf or nano-golf (the latter of which returns something entirely different when put into a Google search). – Joe Z. – 2015-03-28T18:10:27.350
"I haven't seen anybody else post editor-agnostic puzzles" doesn't mean you can't be the first person to make it better. Also it's not like you will lose the "much larger community" of vim golfers by making your challenge inclusive of other editors, too. – Martin Ender – 2015-03-28T18:11:48.900
I had a feeling you might say that. If you can post an Emacs solution that bests the winning vim solution, I'll consider it. – Joe Z. – 2015-03-28T18:16:37.573
27Why is RACECAR not reversed? – orlp – 2015-03-28T19:02:13.500
3Because it's a palindrome. Try reversing it yourself. – Joe Z. – 2015-03-28T19:02:54.090
2Wow, I'm stupid. Derp. – orlp – 2015-03-28T19:03:20.977
7@orlp Lol. I thought you were joking. – mbomb007 – 2015-03-29T02:12:39.280
@mbomb007 Sometimes your brain freezes for a second :) – orlp – 2015-03-29T02:13:05.670
Is the space at the end of the line intentional? If the space isn't there I can get it pretty short. – Caek – 2015-03-30T01:00:08.187
@Caek It would be unfair to me to remove it now - I had to work around it too. Changing the requirements during a challenge (assuming the change isn't necessary) basically invalidates all work by previous competitors and is frowned upon. – orlp – 2015-03-30T01:15:36.733
@Caek: Even if the space weren't there, your program should be able to work around initial and terminal spaces. – Joe Z. – 2015-03-30T01:19:42.013
@orlp I didn't mean to change the question I was just curious. JoeZ: noted. – Caek – 2015-03-30T01:29:17.057