Linux vi Buffer Sort Primer Tutorial

Linux vi Buffer Sort Primer Tutorial

Linux vi Buffer Sort Primer Tutorial

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 with Linux vi C make Primer Tutorial as shown below. And we do today’s work on WordPress 4.1.1’s Linux vi Buffer Sort Primer Tutorial.

We use it a lot during the early days of installing products via the Linux command line … 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 “vi” or “pico” or “emacs” lose out to GUI Mac OS X applications like “TextWrangler” or “TextEdit” is that they do not show text data in overlayable windows, exactly. Well, “exactly” actually, but they can come towards that “overlayable windows” thinking with their “buffer” functionality, to the extent that utilizing buffer functionality can have you swapping between files copying and pasting and “yanking” data among all these many “vi” buffers.

Once upon a time, this “vi” 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 Ella was saying, below, that the GUI applications are “The Rockies”, TextWrangler is clearly “Gibraltar”, but we all love “vi” …

In time the Rockies may crumble
Gibraltar may tumble
They’re only made of clay
But our love is here to stay

Okay, today’s job with buffers, deliberately chosen as a simple but useful one to do, is to …

  1. Open up Mac’s Terminal application and consider a single text file populations.csv
  2. Type vi populations.csv from command line.
  3. Make the cursor go to the first line (via down arrow key once to line 2) to be sorted
  4. Type ma to mark this position “a” (for the buffer)
  5. Move the cursor to the bottom of the text to be sorted
  6. Type !’asort to sort and filter (23 in our case) lines
  7. Type Esc key to get to : ex command section
  8. Type wq! populations.csv to save your sorted file

Please see that this “vi” method of sorting is less unwieldy than others for scenarios where not all the lines of a text file need sorting.

Please review the process with today’s tutorial picture.


Previous relevant Linux vi C make Primer Tutorial is shown below.

Linux vi C make Primer Tutorial

Linux vi C make Primer Tutorial

The Linux (or unix) command vi 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).

So much so, as far as C coding goes, that the creators of vi clearly thought you may “set up shop” in the vi world, because, if you have a makefile, like our simple one for today’s tutorial, you can use vi‘s :make command to compile your C or C++ code while in vi … for those thinking that they never “make” syntax errors in C … hope you know where all the Kryptonite supplies are?

You’ll notice that you can run that compiled code (if successful) and still not leave vi via :!./Hello (where the ! is taking you to the parent shell).

There are other text editors for command line Linux (or unix), some being pico and emacs, and there is a bigger version of vi called vim.

The thing about a lot of command line text editors is that they look unfriendly (it’s less unfriendly if you know {ESC}: gets you to the : prompt from the screen view … 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 TextWrangler (when on a Mac) if there is going to be much cutting, copying and pasting, but you should know that vi has functionality to do with buffers, and some years back, there were maybe 6 or 7 days I’d have preferred to do copying and pasting between buffers using vi … you’re right … I’ll “take a Bex” and lie down now.

Here is a link to some downloadable C code you could call Hello.c and its associated makefile designed for Linux command line compilation via gcc (and here is a good tutorial regarding makefiles for gcc compiler … thanks).

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>