Unformatted text preview:

Text Editing in UNIXAbout These SlidesText Mode EditorsWhat These Slides ContainAbout vivi Versus vimRunning viCaveatNotationModality and Finite State MachinesStarting viA Conceptual Model of viSome General RulesGetting Help on vi and vimInsert ModeLast-Line ModeLast-Line ModeCommand ModeThe Most Important CommandsInsertion CommandsThe BufferCommand CountsGetting StartedAbout picoUsing nano and piconano ScreenshotMore About nanoGraphical EditorsAbout geditWhen Not To Use geditWhat is an X Windows Server?Copyright 2006 Stewart WeissCopyright 2009 Stewart WeissText Editing in UNIXText Editing in UNIXA short introduction to vi, pico, and gedit2 CSci 132 Practical UNIX with PerlAbout UNIX editorsThere are two types of text editors in UNIX: those that run in terminal windows, called text mode editors, and those that are graphical, with menus and mouse pointers. The latter require a windowing system, usually X Windows, to run.If you are remotely logged into UNIX, say through SSH, then you should use a text mode editor. It is possible to use a graphical editor, but it will be much slower to use. I will explain more about that later.3 CSci 132 Practical UNIX with PerlText mode editorsThe three text mode editors of choice in UNIX are vi, emacs, and pico (really nano, to be explained later.)vi is the original editor; it is very fast, easy to use, and available on virtually every UNIX system. The vi commands are the same as those of the sed filter as well as several other common UNIX tools.emacs is the most powerful editor, but it takes more effort to learn how to use it.pico is the easiest editor to learn, and the least powerful.4 CSci 132 Practical UNIX with PerlWhat these slides containThese slides concentrate on vi because it is very fast and always available. Although the set of commands is very cryptic, by learning a small subset of the commands, you can edit text very quickly.What follows is an outline of the basic concepts that define vi. It is not a tutorial; it does not contain specific instructions on the commands in vi. It is intended to supplement a tutorial, which sometimes fails to describe the big picture. I have written a tutorial, which you can download here.5 CSci 132 Practical UNIX with PerlAbout vivi (pronounced vee ai) is the original, full-screen editor for UNIX systems. It has served the UNIX community for more than thirty years, having been written by Bill Joy when he was a graduate student at UC Berkeley in 1976. Before vi was written, the UNIX text editor was a line-oriented editor called ex. vi extended the functionality of ex to give it full-screen capabilities. vi got its name because to get from ex to the full-screen visual editor, you had to type "vi".vi is required to be in all versions of UNIX by the Single UNIX Standard.6 CSci 132 Practical UNIX with Perlvi Versus vimThrough the early 1990's most UNIX users used vi or emacs. But an "improved" version of vi called vim (vi IMproved) was written and released in 1991 by Bram Moolenaar. vim is upward-compatible from vi, so that everything in vi works in vim. vim offers more features than vi, but it is also much harder to learn than vi (unless all you are trying to do is learn the part of vim like vi!)7 CSci 132 Practical UNIX with PerlRunning viOn the system you are using, when you type the vi command in bash, vim runs, because there is an alias in the system /etc/profile that defines vi as /bin/vim. If you want the original vi program, you should either type \vi or /bin/vi (or add a line to unalias vi in your personal .bashrc file.8 CSci 132 Practical UNIX with PerlCaveatIn these slides, unless I write otherwise, what I am describing is vi, not vim. That is, if I say something can be done in vi, it means it can be done in vi and hence in vim also.If I say something cannot be done, it cannot be done in vi but it is possible it can be done in vim.9 CSci 132 Practical UNIX with PerlNotation<CR> denotes the character obtained by pressing the Enter key on the keyboard.<SP> will denote the space character, obtained by pressing the space bar. Sometimes it will be written as an underline "_" instead of <SP>.<ESC> will represent the character obtained by pressing the escape key.A phrase enclosed in angle brackets < > represents the character(s) described by the phrase. For example, <positive integer> will mean any positive integer, and <char> will mean any single character.10 CSci 132 Practical UNIX with PerlModality and finite state machinesvi has three modes, or states. At any given time it is in exactly one of these modes. With each key that you press, it either stays in its current mode or changes to a different one.Things that have a finite number of states and that change their state depending on what events take place, are called finite state machines, or finite automata. Vending machines are finite automata. So are most video games.As an example, a car is always in a specific gear. It can be neutral, first, second, third, fourth, perhaps fifth, and in reverse. Some also have a “parked” gear. The driver or the car itself (in automatic transmissions) changes gears.11 CSci 132 Practical UNIX with PerlStarting viTo edit a file named myfile, at the command prompt, typevi myfile When vi starts it will be in Command Mode.vi is a 3-state finite automaton, with states Command Mode Insert ModeLast-line Mode12 CSci 132 Practical UNIX with PerlA Conceptual model of viThis is a picture of the way that vi works. The arrows from one state to another are labeled by the keys that cause its state to change.INSERT MODECOMMAND MODEi,a,o,c,s,I,A,O,C,S,R:,\,?,!Enter keyEscape keyLAST LINE MODE:, /. ?, !13 CSci 132 Practical UNIX with PerlSome general rulesvi is CASE-SENSITIVE: everything you type must be in the correct case. vi makes a copy of the file in a temporary location to use as its work buffer. Sometimes this copy is readable by other people who know how to find it. This security flaw has been corrected in modern UNIX systems.The cursor in vi is always on a character, not between characters.The start of a line is the leftmost NON-WHITE-SPACE character in that line.The end of a line is the last character before the <CR>, even if it is a white space character.14 CSci 132 Practical UNIX with PerlGetting help on vi and vimThere are no online help facilities in vi.To get help online while using vim, type :help and follow


View Full Document

CUNY CSCI 132 - Text Editing in UNIX

Download Text Editing in UNIX
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Text Editing in UNIX and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Text Editing in UNIX 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?