{"id":4310,"date":"2016-10-27T19:42:35","date_gmt":"2016-10-27T19:42:35","guid":{"rendered":"https:\/\/really.zonky.org\/?p=4310"},"modified":"2016-10-27T19:42:35","modified_gmt":"2016-10-27T19:42:35","slug":"vim-the-ex-mode","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=4310","title":{"rendered":"Vim: The Ex Mode"},"content":{"rendered":"<p>I have recently been &#8216;entertaining&#8217; myself with watching some videos on the\u00a0<em><a href=\"http:\/\/www.vim.org\/\">vim<\/a><\/em> editor which to the uninitiated is an extremely powerful if somewhat &#8216;unusual&#8217; editor that is popular amongst Linux power users. One of the surprising things that came up was that apparently there are experienced\u00a0<em>vim<\/em> users who are not aware of why the\u00a0<em>ex<\/em> mode exists.<\/p>\n<p>Or probably why the\u00a0<em>ex<\/em> command exists.<\/p>\n<p>In the dim and distant past (and in fact even longer than I&#8217;ve used Unix!), one of the possible ways of interacting with computers was with a printing terminal :-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/4\/41\/Teletype_with_papertape_punch_and_reader.jpg\/800px-Teletype_with_papertape_punch_and_reader.jpg\" alt=\"\" width=\"800\" height=\"1067\" \/><\/p>\n<p>On such a terminal, using a visual editor like\u00a0<em>vim<\/em> (or it&#8217;s predecessor\u00a0<em>vi<\/em>) would have been painful. Redrawing the screen would take a couple of minutes or more; imaging moving the cursor across from the beginning of the line to the end!<\/p>\n<p>So it was common to use an alternative kind of editor &#8211; the\u00a0<em>line editor<\/em>. The process of creating a file is somewhat clumsy :-<\/p>\n<pre>$ <strong>ex ~\/Foo<\/strong>\r\n\"~\/Foo\" 1L, 4C\r\nEntering Ex mode.  Type \"visual\" to go to Normal mode.\r\n:<strong>p<\/strong>\r\nFoo\r\n:<strong>a<\/strong>\r\nBar\r\n<strong>.<\/strong>\r\n:<strong>p<\/strong>\r\nBar\r\n:<strong>1<\/strong>\r\nFoo\r\n:write\r\n:quit<\/pre>\n<p>Now for a quick explanation (although this is no tutorial on line editors!): The\u00a0<em>ex ~\/Foo<\/em> is the command given to start editing a pre-existing file called\u00a0<em>Foo<\/em> in the\u00a0<em>ex<\/em> editor. After the editor starts up, I enter the &#8220;p&#8221; command to print the current line. I then use the &#8220;a&#8221; command to append text after the first line, and enter a &#8220;.&#8221; on it&#8217;s own to finish adding lines. Again I use &#8220;p&#8221; to print the current line, and then &#8220;1&#8221; to print the first line.<\/p>\n<p>Which is more than you&#8217;ll ever want to know about how to use\u00a0<em>ex<\/em>, so why does it still exist?<\/p>\n<p>The first reason is simply because it&#8217;s possible. It&#8217;s almost certainly fairly easy to support the\u00a0<em>ex<\/em> mode with\u00a0<em>vim<\/em>; after all the ex-mode is effectively the commands you get when you enter &#8220;:&#8221; within\u00a0<em>vim<\/em>.<\/p>\n<p>The next reason is that line editors were sometimes used within shell scripts to batch edit files, and somewhere out there is a shell script from hell that relies on\u00a0<em>ex<\/em> to keep running.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have recently been &#8216;entertaining&#8217; myself with watching some videos on the\u00a0vim editor which to the uninitiated is an extremely powerful if somewhat &#8216;unusual&#8217; editor that is popular amongst Linux power users. One of the surprising things that came up was that apparently there are experienced\u00a0vim users who are not aware of why the\u00a0ex mode <a href='https:\/\/really.zonky.org\/?p=4310' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[4,6],"tags":[1461,1462,1460,1459],"class_list":["post-4310","post","type-post","status-publish","format-standard","hentry","category-it","category-history","tag-ex","tag-teletype","tag-vi","tag-vim","category-4-id","category-6-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-17w","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/4310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4310"}],"version-history":[{"count":3,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/4310\/revisions"}],"predecessor-version":[{"id":4313,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/4310\/revisions\/4313"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}