{"id":22373,"date":"2016-05-31T03:01:29","date_gmt":"2016-05-30T17:01:29","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=22373"},"modified":"2020-06-10T10:27:45","modified_gmt":"2020-06-10T00:27:45","slug":"linux-vi-buffer-sort-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-vi-buffer-sort-primer-tutorial\/","title":{"rendered":"Linux vi Buffer Sort Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/vi_buffer_sort.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux vi Buffer Sort Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/vi_buffer_sort.jpg\" title=\"Linux vi Buffer Sort Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux vi Buffer Sort Primer Tutorial<\/p><\/div>\n<p>The Linux (or unix) command <a target=_blank title='vi' href='http:\/\/pic.dhe.ibm.com\/infocenter\/zos\/v1r13\/topic\/com.ibm.zos.r13.bpxa400\/vi.htm?resultof=%22%76%69%22%20'><i>vi<\/i><\/a> is a powerful command line editor tool which has a long history with unix, may have a long learning curve for beginners, perhaps.  Our last tutorial about the <i>vi<\/i> command line text editor was with <a title='Linux vi C make Primer Tutorial' href='#lvcmpt'>Linux vi C make Primer Tutorial<\/a> as shown below.  And we do today&#8217;s work on WordPress 4.1.1&#8217;s <a target=_blank title='Linux vi Buffer Sort Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-vi-buffer-sort-primer-tutorial\/'>Linux vi Buffer Sort Primer Tutorial<\/a>.<\/p>\n<p>We use it a lot during the early days of installing products via the Linux command line &#8230; our thinking when we go to the Terminal application with Mac OS X and talk to its BSD code based operating system.  One of the reasons such command line text editors like &#8220;vi&#8221; or &#8220;pico&#8221; or &#8220;emacs&#8221; lose out to GUI Mac OS X applications like &#8220;TextWrangler&#8221; or &#8220;TextEdit&#8221; is that they do not show text data in overlayable windows, exactly.  Well, &#8220;exactly&#8221; actually, but they can come towards that &#8220;overlayable windows&#8221; thinking with their &#8220;buffer&#8221; functionality, to the extent that utilizing buffer functionality can have you swapping between files copying and pasting and <a target=_blabk title='vi advice tals about yank' href='https:\/\/docs.oracle.com\/cd\/E19455-01\/806-2902\/editorvi-53\/index.html'>&#8220;yanking&#8221;<\/a> data among all these many &#8220;vi&#8221; buffers.<\/p>\n<p>Once upon a time, this &#8220;vi&#8221; buffer way was the only way to do this text editing, so perhaps we should cut it some slack, and give it a go in case one day you need it.  After all, its pretty obvious <a target=_blank title='?' href='http:\/\/www.azlyrics.com\/lyrics\/ellafitzgerald\/loveisheretostay.html'>Ella<\/a> was saying, below, that the GUI applications are &#8220;The Rockies&#8221;, TextWrangler is clearly &#8220;Gibraltar&#8221;, but we all love &#8220;vi&#8221; &#8230;<\/p>\n<blockquote cite=\"http:\/\/www.azlyrics.com\/lyrics\/ellafitzgerald\/loveisheretostay.html\"><p>\nIn time the Rockies may crumble<br \/>\nGibraltar may tumble<br \/>\nThey&#8217;re only made of clay<br \/>\nBut our love is here to stay\n<\/p><\/blockquote>\n<p>Okay, today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/vi_buffer_sort.jpg\" title='Click picture'>job<\/a> with buffers, deliberately chosen as a simple but useful one to do, is to &#8230;<\/p>\n<ol>\n<li>Open up Mac&#8217;s Terminal application and consider a single text file <a target=_blank title='populations.csv before' href='http:\/\/www.rjmprogramming.com.au\/Mac\/populations.csv_GETME'>populations.csv<\/a><\/li>\n<li>Type <code>vi populations.csv<\/code> from command line.<\/li>\n<li>Make the cursor go to the first line (via down arrow key once to line 2) to be sorted<\/li>\n<li>Type <b>m<i>a<\/i><\/b> to mark this position &#8220;<i>a<\/i>&#8221; (for the buffer)<\/li>\n<li>Move the cursor to the bottom of the text to be sorted<\/li>\n<li>Type <b>!&#8217;<i>a<\/i>sort<\/b> to sort and filter (23 in  our case) lines<\/li>\n<li>Type <b>Esc<\/b> key to get to : ex command section<\/li>\n<li>Type <b>wq! <a target=_blank title='populations.csv before' href='http:\/\/www.rjmprogramming.com.au\/Mac\/populations.csv-GETME'>populations.csv<\/a><\/b> to save your sorted file<\/li>\n<\/ol>\n<p>Please see that <a target=_blank title='populations.csv before' href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Mac\/populations.csv-GETME'>this &#8220;vi&#8221; method of sorting<\/a> is less unwieldy than others for scenarios where not all the lines of a text file need sorting.<\/p>\n<p>Please review the process with today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/vi_buffer_sort.jpg\" title='Click picture'>tutorial picture<\/a>.<\/p>\n<hr>\n<p id='lvcmpt'>Previous relevant <a target=_blank title='Linux vi C make Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-vi-c-make-primer-tutorial\/'>Linux vi C make Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/vi\/Linux_vi_make.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux vi C make Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/vi\/Linux_vi_make.jpg\" title=\"Linux vi C make Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux vi C make Primer Tutorial<\/p><\/div>\n<p>The Linux (or unix) command <a target=_blank title='vi' href='http:\/\/pic.dhe.ibm.com\/infocenter\/zos\/v1r13\/topic\/com.ibm.zos.r13.bpxa400\/vi.htm?resultof=%22%76%69%22%20'><i>vi<\/i><\/a> is a powerful command line editor tool which has a long history with unix and the maintenance of C code (as just one example of its uses).<\/p>\n<p>So much so, as far as C coding goes, that the creators of <i>vi<\/i> clearly thought you may &#8220;set up shop&#8221; in the <i>vi<\/i> world, because, if you have a makefile, like our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/vi\/makefile._GETME\" title='makefile'>simple one<\/a> for today&#8217;s tutorial, you can use <i>vi<\/i>&#8216;s :<i>make<\/i> command to compile your C or C++ code while in <i>vi<\/i> &#8230; for those thinking that they never &#8220;make&#8221; syntax errors in C &#8230; hope you know where all the <a target=_blank href='https:\/\/www.youtube.com\/watch?v=A0xTEUBEQUs' title='Kryptonite'>Kryptonite<\/a> supplies are?<\/p>\n<p>You&#8217;ll notice that you can run that compiled code (if successful) and still not leave <i>vi<\/i> via :<i>!.\/Hello<\/i> (where the ! is taking you to the parent shell).<\/p>\n<p>There are other text editors for command line Linux (or unix), some being <a target=_blank title='pico' href='http:\/\/info.eps.surrey.ac.uk\/FAQ\/pico.html'>pico<\/a> and <a target=_blank title='emacs' href='http:\/\/www.cs.colostate.edu\/helpdocs\/emacs.html'>emacs<\/a>, and there is a bigger version of vi called <a target=_blank title='vim' href='http:\/\/www.vim.org\/'>vim<\/a>.<\/p>\n<p>The thing about a lot of command line text editors is that they look unfriendly (it&#8217;s less unfriendly if you know {ESC}: gets you to the : prompt from the screen view &#8230; second green arrow in tutorial picture included this), and that can be true, and this has lead me to do more work with the GUI <a target=_blank href='http:\/\/www.macupdate.com\/app\/mac\/11009\/textwrangler' title='Mac TextWrangler text editor'>TextWrangler<\/a> (when on a Mac) if there is going to be much cutting, copying and pasting, but you should know that <i>vi<\/i> has functionality to do with buffers, and some years back, there were maybe 6 or 7 days I&#8217;d have preferred to do copying and pasting between buffers using <i>vi<\/i> &#8230; you&#8217;re right &#8230; I&#8217;ll <a target=_blank href='https:\/\/www.youtube.com\/watch?v=BF6ffbz70SY' title='Take a Bex and lie down'>&#8220;take a Bex&#8221;<\/a> and lie down now.<\/p>\n<p>Here is a link to some downloadable C code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/vi\/Hello.c_GETME\" title='Hello.c'>Hello.c<\/a> and its associated <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/vi\/makefile._GETME\" title='makefile'>makefile<\/a> designed for Linux command line compilation via <a target=_blank title='vi' href='http:\/\/gcc.gnu.org\/'><i>gcc<\/i><\/a> (and here is a good tutorial regarding <a target=_blank href='http:\/\/stackoverflow.com\/questions\/1484817\/how-do-i-make-a-simple-makefile-gcc-unix' title='gcc makefiles'>makefiles<\/a> for <i>gcc<\/i> compiler &#8230; thanks).<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d8497' onclick='var dv=document.getElementById(\"d8497\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=text-editor\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8497' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d8497' onclick='var dv=document.getElementById(\"d8497\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=text-editor\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8497' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux (or unix) command vi is a powerful command line editor tool which has a long history with unix, may have a long learning curve for beginners, perhaps. Our last tutorial about the vi command line text editor was &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-vi-buffer-sort-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[168,234,1822,707,725,1173,1255,1319,1339,1368],"class_list":["post-22373","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-buffer","tag-command-line","tag-editor","tag-linux","tag-mac-os-x","tag-sort","tag-text-editor","tag-tutorial","tag-unix","tag-vi"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22373"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=22373"}],"version-history":[{"count":13,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22373\/revisions"}],"predecessor-version":[{"id":49251,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/22373\/revisions\/49251"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=22373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=22373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=22373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}