AMITIAE - Friday 5 October 2012


Command Line Work: New Users and Terminal (12) -- Installed Text Editors - emacs, nano, pico, vi and vim


apple and chopsticks



advertisement


By Graham K. Rogers


Terminal


Ever since the first Macs appeared, they have been known for the graphical user interface (GUI): icons instead of command line work which before the mid-1980s was the norm. Paradoxically, the arrival of OS X brought with it easy access to the command line should users ever want this, although it is possible to use the computer without ever needing to work at the command line at all.


I am sometimes exasperated by those who reach for a mega-application like Word just to write a brief memo or a few words in a letter. Apart from not having this installed, I tend to use Apple's Pages in the rare case I need such formatting; or TextEdit for creating rich text or document files: quite enough for teaching materials. When I write articles for print or online use, I favour BareBones' TextWrangler although lately I have been using WriteRoom as well because of the versions for OS X and iOS and because of its DropBox integration. Both TextWrangler and WriteRoom create basic text.

There are over 30 text editors for Unix and a few of these are included in the Unix installation on OS X. Unlike the word processors we are now used to, some of these, like emacs, evolved from teletype editors as would be expected considering the Bell Labs genesis of Unix. They are a little more complex until the user is familiar with the commands.

The intention here is to be informative rather than instructive: users should make their own discoveries and form preferences. However, as well as indicating the way in to each utility, I will provide the way out.


emacs

There is a manual entry for emacs which may be accessed via the usual command, man emacs which reveals, among a host of commands, that Emacs was written by Richard Stallman and the Free Software Foundation. It has been under development since first produced in the late 1970s.

The editor is started by typing emacs at the command line, which brings up a brief information page. The text here refers to C-l to begin editing. This type of instruction is used throughout and refers to the Control key + the letter L.


emacs


Typing this clears the mini-help-file and the user is able to use a buffer. There are instructions on how to save the text created: by use of Control x and Control f. By default the file is saved in the /usr/local/bin/ folder. By deleting that location and dragging a file or folder to the command line files may be saved in a more accessible location, such as the desktop.

Quitting emacs can be done in one of two ways: by using Control + Z which stops the process; or by use of Control X then Control C (Control X plus Control H brings up a list of key translations).


As a note, while preparing this, I saw an item by Paul Horowitz, on OS X Daily (one of my regular reads): "5 Stupid Terminal Tricks to Keep You Entertained". One of the tricks outlines a number of games built in to emacs that can be accessed by pressing the ESC key and then ` (the key to the left of 1). That brings up the menu: then t, then g. There is a list of 11 games.


Nano and Pico

Of all the Unix text editors, I prefer Pico because of its relationship to the email program Pine, itself now developed into Alpine. This is still available on the server I sometimes access at my university. Pico is one of the text editors installed on the Mac which can be used in Terminal. It has now been developed under the name of Nano because of licensing problems of the original. This may be accessed by typing either pico or nano at the command line.

Compared to emacs the user has a wealth of usable information (relatively speaking) displayed at the bottom of the screen, although some may not appear to be logical: Control G (not Control H) opens the Help file, for example. Although shown in the list of commands, there is no spell-checker installed for the version I am using.

As with emacs and with locating files within Unix, it may be easier for the user to open a file (or folder location) by dragging it to the command line of Nano/Pico. Rather than "Save" a user needs to WriteOut a file, which in some cases needs permission to over-write a file. Exiting the utility is simply done, by using the Command + X keys.


Vi and Vim

The text editor VIM is an IMproved version of Vi (VIsual editor). This may be accessed in Terminal on OS X by typing in either of those commands, as well as view, rvim or rview. We may also use ex which gives the options of "ex mode" or "visual mode". I must admit that I find Vim not as intuitive as I would like.


Vim


To start the editor we type vim (or one of the other commands) and a filename. The file will be opened, but if it does not exist it will be created. Users work in "Insert" mode which can be closed by pressing the ESC key.

Commands are entered by typing a colon in the first column and a letter or word that relates to the action. To exit, we would type

:q


While help (which splits the Terminal display -- top and bottom) is

:help


Vi, or Vim like emacs has a rich set of commands and some of these may be revealed by a sub-section to help:

:help quickref

There are a number of other files that may be useful:

  • quickref - Overview of the most common commands you will use
  • tutor - 30 minutes training course for beginners
  • copying - About copyrights
  • iccf - Helping poor children in Uganda
  • sponsor - Sponsor Vim development, become a registered Vim user
  • www - Vim on the World Wide Web
  • bugs - Where to send bug reports


Vim


There is also an online resource at Colorado University with some fairly easy to grasp comments on how to work with Vi (or Vim).


A note on Visudo: Usually an Admin account is the only one able to use the sudo command, but there is a way to add a user to the sudoers file. This is not available in a user account and may only be accessed using the sudo command, plus the utility name, in the Admin account with the Admin password required. There are so many barriers here and such a risk that it is far easier to set up a second Admin account (or ask the Admin user) for any necessary work. As ever, there is information about this if a user types in the command,

man visudo

Visudo which is structured like Vi and Vim, has a specific task here and should only be used if you absolutely know what you are doing: as with any of the commands, If in doubt, Don't.


To be continued. . . .



See Also -

  • New Users and Terminal (1) -- A Quick Look Round
  • New Users and Terminal (2) -- Basic Navigation
  • New Users and Terminal (3) -- Shell Basics
  • New Users and Terminal (4) -- Lists and Manuals
  • New Users and Terminal (5) -- Internet Use
  • New Users and Terminal (6) -- Questions of Identity
  • New Users and Terminal (7) -- A Little More Discovery
  • New Users and Terminal (8) -- File Commands and More
  • New Users and Terminal (9) -- Process Identification and Termination
  • New Users and Terminal (10) -- Browsing the Web using Unix
  • New Users and Terminal (11) -- Unix Tricks from OS X Daily
  • New Users and Terminal (13) -- Installing and Using the Utility, WGET
  • New Users and Terminal (14) -- Passwords, Purging and Closing Notes
  • New Users and Terminal (15) -- Permissions and chmod


    Graham K. Rogers teaches at the Faculty of Engineering, Mahidol University in Thailand. He wrote in the Bangkok Post, Database supplement on IT subjects. For the last seven years of Database he wrote a column on Apple and Macs.


  • advertisement



    Google


    Made on Mac

    For further information, e-mail to

    information Tag information Tag

    Back to eXtensions
    Back to Home Page