{"id":1499,"date":"2012-12-18T06:42:00","date_gmt":"2012-12-18T11:42:00","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=1499"},"modified":"2012-12-18T06:43:37","modified_gmt":"2012-12-18T11:43:37","slug":"a-solution-to-the-vimgolf-in-emacs-riff","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=1499","title":{"rendered":"A Solution to the VimGolf in Emacs Riff"},"content":{"rendered":"<p>Recall that the <a href=\"http:\/\/irreal.org\/blog\/?p=1493\">last VimGolf in Emacs challenge<\/a> was to convert<\/p>\n<pre class=\"example\">abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz<\/pre>\n<p>to<\/p>\n<pre class=\"example\">a b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\na b c d e f g h i j k l m n o p q r s t u v w x y z<\/pre>\n<p>I found this harder than I expected. It&#8217;s pretty easy to put a space after each character but then you have to deal with the spaces after the z in each line. The <a href=\"http:\/\/irreal.org\/blog\/?p=1489\">previous challenge<\/a> was easier because all we had to do was find the blanks and replace each of them with four blanks. In this case we want to insert a blank after each character unless it&#8217; the last character in the line.<\/p>\n<p>Here&#8217;s my solution:<\/p>\n<table border=\"2\" frame=\"hsides\" rules=\"groups\" cellspacing=\"0\" cellpadding=\"6\">\n<colgroup>\n<col class=\"left\" \/>\n<col class=\"left\" \/> <\/colgroup>\n<tbody>\n<tr class=\"tr-odd\">\n<td class=\"left\">\u3010<kbd>Ctrl<\/kbd>+<kbd>Meta<\/kbd>+<kbd>%<\/kbd>\u3011<\/td>\n<td class=\"left\">Invoke <code>query-replace-regexp<\/code><\/td>\n<\/tr>\n<tr class=\"tr-even\">\n<td class=\"left\">\u3010<kbd>.<\/kbd> <kbd>\\<\/kbd> <kbd>B<\/kbd> <kbd>Return<\/kbd>\u3011<\/td>\n<td class=\"left\">Match every character except the last in the line<\/td>\n<\/tr>\n<tr class=\"tr-odd\">\n<td class=\"left\">\u3010<kbd>\\<\/kbd> <kbd>&amp;<\/kbd> <kbd>Space<\/kbd> <kbd>Return<\/kbd>\u3011<\/td>\n<td class=\"left\">Replace with the match followed by a space<\/td>\n<\/tr>\n<tr class=\"tr-even\">\n<td class=\"left\">\u3010<kbd>!<\/kbd>\u3011<\/td>\n<td class=\"left\">Run for the entire buffer<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>That&#8217;s a total of 10 keystrokes. Not too bad, but <a href=\"http:\/\/irreal.org\/blog\/?p=1493#comment-73133\">Aaron Culich<\/a> managed to shave off 3 (!) more keystrokes by realizing that you don&#8217;t have to match the letters, just the empty spaces between them. Thus the regexp for the FROM string is just <code>\\B<\/code>, which means that the TO string is just SPACE for a total of 7 keystrokes. If you can do better, be sure to leave a comment. If you&#8217;re a Vim expert, how many keystrokes does it take you?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recall that the last VimGolf in Emacs challenge was to convert abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz to a b &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=1499\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-1499","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1499"}],"version-history":[{"count":3,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1499\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1499\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}