Here’s an interesting VimGolf challenge that nicely demonstrates the power of CUA selection mode. Given the word frequency chart
align here the 56271872 of 33950064 and 29944184 to 25956096 in 17420636 I 11764797 that 11073318 was 10078245 his 8799755 he 8397205 it 8058110
align the frequency counts so that it looks like
align here the 56271872 of 33950064 and 29944184 to 25956096 in 17420636 I 11764797 that 11073318 was 10078245 his 8799755 he 8397205 it 8058110
My first thought was to use align-regexp
but that command doesn’t have a shortcut key sequence and the best regular expression I could find was [1-9]
. A pretty nice solution but it certainly won’t win on keystrokes.
After messing around a bit, I came up with a solution of 4 keystrokes using the CUA rectangle functionality.
【Meta+m】 | Move to the a in align |
【Ctrl+Return】 | Invoke rectangle mode |
【Meta+}】 | Move to end of buffer |
【Meta+a】 | Align the rectangle |
Notice that the trailing digits of a few of the frequency counts aren’t in the rectangle but they get dragged along anyway. I’ve only been using CUA rectangle mode for a short while but I am continually amazed at how powerful it is. Certainly this problem doesn’t look like a rectangle problem but CUA rectangle mode solves it very handily anyway.
Sadly, those darn Vim people were able to solve this in 3 keystrokes so if you can shave off a stroke or two be sure to leave a comment. I don’t think you can squeeze any more keystrokes out of the rectangle strategy so you’ll probably need something entirely different.