{"id":2067,"date":"2009-07-13T19:44:44","date_gmt":"2009-07-13T23:44:44","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=2067"},"modified":"2009-07-13T19:44:44","modified_gmt":"2009-07-13T23:44:44","slug":"mastering-your-tools","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2009\/07\/13\/mastering-your-tools\/","title":{"rendered":"Mastering your tools"},"content":{"rendered":"<p>One thing I&#8217;ve found with computers is that most people only learn the basics of many of the tools they use daily. Articles like <a href=\"http:\/\/firstclassthoughts.co.uk\/misc\/best_firefox_shortcuts.html\">My top 8 time-saving Firefox shortcuts<\/a> are great ways to quickly pick up on the little things I never knew about (Ctrl+K to jump to the search bar, and Ctrl+L to jump to the URL bar!).<\/p>\n<p>Today I found myself with a badly-formatted CSV file. Many of the last columns had newlines in them, which isn&#8217;t something a CSV should have. I fired up vim, and after a couple minutes, found out the regular expression to find any line that <em>doesn&#8217;t<\/em> end with a quotation mark: \/[^&#8221;]$\/ will do that. (Aside: regular expressions are giant pains, but I don&#8217;t know of any easier way to do what they do. I could write code to iterate over every line, but then I&#8217;ve got 15 lines of code instead of five obscure characters.)<\/p>\n<p>Pressing &#8220;n&#8221; jumps to the next pattern matching that, and &#8220;J&#8221; pulls up the previous line to the current line. &#8220;n&#8221; again to the next match, and then &#8220;.&#8221; (easier than Shift+j for an uppercase) repeats the J. I soon realized that there were more instances than I thought, though. The ideal way would be have a regular expression to do the replacement, too, but I couldn&#8217;t find an easy way, so I did the next best thing and defined a macro. &#8220;qr&#8221; defined a macro named &#8220;r&#8221;, and pressing &#8220;n&#8221; and then &#8220;J&#8221;, the two steps from above, recorded them as a macro. &#8220;q&#8221; again stopped recording, and then &#8220;@r&#8221; ran the macro. Of course, &#8220;@r&#8221; (@@ does the same thing) wasn&#8217;t much easier to type than &#8220;n.n.n.n.n.n.n.&#8221; over and over.<\/p>\n<p>So I ran &#8220;100@r&#8221; to run the macro 100 times. I realized that there were <em>way<\/em> more cases than I thought, and &#8220;10000@r&#8221; finished it off.<\/p>\n<p>I was left noticing a few things. One is that many of these things were really obscure. To a UNIX power-user, it&#8217;s perhaps cake, but to a more average user, it&#8217;s black magic. I decided a while ago to make an effort to really learn vi. I&#8217;m only a small fraction of the way to mastery, but I&#8217;ve found that the time I invested in learning the lesser-known features has been well worth it.<\/p>\n<p>Another thing I wonder about is how I could have done this more effectively. It seems like there ought to be a way to run a vim command for every spot that a regular expression matches. And putting a huge number in front of a macro to run it as many times as needed seems like a hack. At the same time, I know that using a heavyweight text editor was a no-go. This was an enormous file and text editors were dying under the load of trying to deal with the whole document. vim doesn&#8217;t mind a gigantic file.<\/p>\n<p>I&#8217;ve learned some handy shell tricks and more about MySQL in the past year, too, and both have gotten me far. It sometimes doesn&#8217;t seem worth the time, but every time I&#8217;ve made an effort to really master all the nuances of a tool, I&#8217;ve recouped my time investment many times over.<\/p>","protected":false},"excerpt":{"rendered":"<p>One thing I&#8217;ve found with computers is that most people only learn the basics of many of the tools they use daily. Articles like My top 8 time-saving Firefox shortcuts are great ways to quickly pick up on the little &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2009\/07\/13\/mastering-your-tools\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2067","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=2067"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2067\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=2067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=2067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=2067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}