Nano-Liquids, Nano-Particles, Nano-Wetting: X-ray Scattering Studies
Editors - Iowa State University · Full Screen Editors pico/nano Exercise – Inserting Text from...
Transcript of Editors - Iowa State University · Full Screen Editors pico/nano Exercise – Inserting Text from...
EditorsA Brief History
Early programmers used punch cards
Make a mistake? Make a new card
Editors are associated with terminals
First terminals were teletypes – “wired” typewriters
Teletypes printed one line at a time
Editors
A Brief History – Line Editors
For teletypes, use a line editor
Line editors make corrections on a linebyline basis
Give a line number or multiple line numbers and execute a command on that line or those lines
EditorsA Brief History – Full Screen Editors
Later terminals were based on cathode ray tubes and allowed for screen drawing
Screen drawing meant manipulation of characters on the screen
Access to the full screen led to the development of full screen editors
EditorsA Brief History – Full Screen Editors
Full screen editors allow the user to move the cursor to any point in the file and modify text in place
Full screen editors allow the marking, copying, cutting and pasting of full sections of text. Line editors allowed this as well but not as easily
The mouse (pointing device) made this process even simpler
Editors
Full Screen Editors
Many editors now available for use in UNIX:
● vi● emacs/xemacs ● joe● pico/nano● nedit● Open Office?
EditorsFull Screen Editors
Learn the most crucial commands first:
● Starting the editor● Moving around the file● Inserting text● Deleting text● Undoing changes● Saving the text● Exiting the editor
EditorsFull Screen Editors pico/nano
pico comes with the Pine mail package. nano is the “free” version of pico
pico is easy to use. Commands are listed at the bottom of the screen for easy reference
Commands are tied to control characters
EditorsFull Screen Editors pico/nano
Exercise – Creating a New File
Open a new file# nano myfile
Enter some text
Save the file with CTRLX, answer “yes” and hit ENTER
Editors
Full Screen Editors pico/nano
Exercise – Copying and Pasting Text
Open an existing file# nano myfile
Position the cursor at a line of textEnter CTRLK to cut that lineEnter CTRLU to paste that line multiple times. Make about 30 copies of the lineSave the file (CTRLX, Yes, ENTER)
Editors
Full Screen Editors pico/nano
Exercise – Moving Around the File
Open an existing file# nano myfile
Use the arrow keys to move the cursor
User CTRLV to move down a page
Use CTRLY to move up a page
Editors
Full Screen Editors pico/nano
Exercise – Finding Text (Searching)
Open an existing file (if not already open)# nano myfile
User CTRLW to find a particular word or phrase
Editors
Full Screen Editors pico/nano
Exercise – Inserting Text from Another File
Open an existing file (if not already open)# nano myfile
User CTRLR to read in the contents of your bash startup script (~/.bashrc)
Without exiting the editor, save the file to another file called myfile2 using CTRLO
Editors
Full Screen Editors pico/nano
Exercise – Getting Help
Open an existing file (if not already open)# nano myfile
User CTRLG to see the help documentation on other commands
Editors
Full Screen Editors vi
vi is the oldest but most used screen editor in UNIX.
It inherits the commands from the UNIX line editors ed and ex
vi gets its name from being the visual editor
Editors
Full Screen Editors vi
vi has two modes:
● Command – you enter line editor commands and extended commands
● Insert – as its name suggests, you insert text in this mode
Editors
Full Screen Editors – viInsert Mode
vi begins in command mode. To enter insert mode, enter the i key
Text can then be freely entered and deleted and, in some incarnations of vi, you can use your cursor to move around the file
Exit insert mode and return to command mode using either the Escape key or CTRL[
EditorsFull Screen Editors – vi
Command Mode Movement
● One character at a time j,k,l or h keys or the arrow keys
● One word at a time:
w – beginning of the next word
e– end of the next word
b – beginning of the previous word
EditorsFull Screen Editors – vi
Command Mode Movement
● One line at a time CTRLN, CTRLP
● One half page at a time – CTRLD, CTRLU
● One full page at a time – CTRLF, CTRLB
● File at a time – SHIFTG, 1 SHIFTG
EditorsFull Screen Editors – vi
Exercise – Modifying and Saving a File
Open a file# vi myfile
Go into insert mode with the i key
Enter some text
Go to command mode with the Escape key
Exit and save the file with :wq!
EditorsFull Screen Editors – vi
Exercise – Moving Around the File
Open a file# vi myfile
Perform single character, single word, single line and page movement
h,j,k,l and arrow keysb, w, eCTRLN, CTRLPCTRLD,CTRLU,CTRLF,CTRLB
Exit without saving the file with :q!
EditorsFull Screen Editors – vi
Exercise – Searching for Text
Open a file
# vi myfile
Look for a word using the search command key /
Exit without saving the file using :q!
EditorsFull Screen Editors – vi
Exercise – Copying and Pasting
Open a file# vi myfile
Pick a line and move the cursor to that line
Enter CTRLY to copy that line
Move to another part of the file
Use the p key to paste the line
EditorsFull Screen Editors – vi
Exercise – Cutting and Pasting
Open a file# vi myfile
Pick a line and move the cursor to that line
Enter dd to cut that line
Move to another part of the file
Use the p key to paste the line
EditorsFull Screen Editors – vi
Exercise – Applying Commands to Multiple Lines
Remember – vi is based on a line editor. To apply a command many times, enter the number of lines before entering the command
Open a file# vi myfile
Pick a line and move the cursor to that lineEnter 3dd to cut three linesMove to another part of the fileUse the p key to paste the lines
EditorsFull Screen Editors – vi
Line Editor Commands
vi inherits all the commands used by ed and ex. In command mode, precede one of these commands with a colon (:). Some useful commands include:
● :i insert before ● :a append after● :s substitute text on lines that match a pattern
For both :i and :a, exit the insert mode by typing a period (.) on a line by itself
EditorsFull Screen Editors – vi
Exercise – Substituting Text
The form of the substitution command is
:s/pattern/replacement/
Move the cursor to a line and try to substitute one word for another
:s/this/that/
EditorsPattern Matching – Regular Expressions
Pattern matching uses a sophisticated and powerful symbolic language known as regular expressions
A complicated pattern can be built from a few (of many) simple symbols:
● ^ Matches the beginning of the line● $ Matches the end of the line● . Matches any single character● * Will match zero or more occurrences of the previous character● [ ] Matches all the characters inside the [ ]
EditorsPattern Matching – Regular Expressions
Examples:
th.* – would match both this and that
now .*s the time – would match now is the time and now was the time
^# would match all comments in a shell script
Editors
Pattern Matching – Regular Expressions
Regular expressions are used by many UNIX commands and programming languages for pattern matching:
● Sed – the stream editor● Grep – get regular expressions● Awk● Perl
Editors
Pattern Matching – Regular Expressions
sed
sed can be very powerful in shell scripts by modifying text on the fly using pipes
Examples:
● /usr/bin/tty | sed e 's/\/dev\/pts\//My tty number is /'● /sbin/ifconfig | sed n e 's/.*inet addr:\(.*\)Bcast.*/\1/p'
EditorsLine Editor Commands
What to do if your system fails and you only have access to the root partition?You may only have ed.
# ed myfile1,$p1ps/now/then/wq