16
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers(g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

Embed Size (px)

Citation preview

Page 1: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

1

Unix Editors (ee, ed, ex, vi, vim) and Compilers(g77, gcc)

Speaker: Li-Wen Chen

Date: 2011-07-19

Page 2: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

2

Introduction

line-oriented editoredex

screen oriented editoree vi - a screen-based editor used by many Unix

users. vim - Vi IMproved

Page 3: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

3

ed

Starting the ed Editor $ ed [ filename ]

[ ] means it is optionalAfter entering, ed is in command mode.

command modeallows the entry of commands to manipulate texta – (append) go to input mode

input modeputs anything typed on the keyboard into the current file. – terminate input mode

Commands about quit ed w – write (save file) q - quit

Page 4: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

4

Other ed commands

a – append after the specified line i – insert before the specified linec – change the specified line

. – the current line , or % - the first line$ - the last line

l – list (print, display)d – deleteu – undo

Key in the character,and then enter input mode

Page 5: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

5

vi

Starting the VI Editor $ vi [ filename ]

After entering command mode

allows the entry of commands to manipulate text i – (insert) go to insert mode

insert modeputs anything typed on the keyboard into the current fileEsc – go to command mode

Commands about quit vi :q – quit the vi editor :w – write (save file) :wq or ZZ – write and quit :q! – force vi to quit

Page 6: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

6

Inserting New Text

I – insert from the beginning of the current lineA – append at the end of the current line

a – append after the current cursor position i – insert before the current cursor position

O – create a new line above the current cursor positiono – create a new line below the current cursor position

Type these characters, and then enter insert mode.

Page 7: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

7

Type Commands

[count] commandcommand – most commands are one

character longcount – a number, any character from 1 to 9

Ex: 10xx – delete a characters under the cursor10x – delete 10 characters at a time

Page 8: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

8

Moving the Cursork - ↑, move the cursor up one line. j - ↓, move the cursor down one line. h - ←, move the cursor to the left one character position. l - →, move the cursor to the right one character

position.

^ - Move the cursor to the first non-whitespace character.

$ - Move the cursor to the end of the current line.

% - Move the cursor to the matching parenthesis or brace.

Page 9: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

9

Moving the Cursor (cont.)

ctrl F Scroll forwards one page. A count scrolls that many pages.

ctrl B Scroll backwards one page. A count scrolls that many pages.

ctrl D Scroll forwards half a window. A count scrolls that many lines.

ctrl U Scroll backwards half a window. A count scrolls that many lines.

G - Go to the line number specified as the count. If no count is given, then go to the end of the file.

gg - go to the beginning of the file

Page 10: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

10

Edit

r - replace one character under the cursor. x - delete character under the cursor. ~ - Switch the case of the character under the cursor. u - undo the last change to the file.

d^ - delete from current cursor position to the beginning of the line.

d$ - delete from current cursor position to the end of the line. dw - delete from current cursor position to the end of the word. 3dd - delete three lines from current cursor position downwards.

y (copy) and p (paste) are similar to d.

Page 11: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

11

Search and Replace

/ - Search the file downwards for the string specified after the /. ? - Search the file upwards for the string specified after the ?. n - Repeat the last search given by '/' or '?' N - Repeat the last search given by '/' or '?‘, but in opposite direction

< > For example: /\<the\> should find only word the, but not words like these: there

and other.

:s . – current position $ - the last line for example:

:1,$ s/buffer/BUF/ from first line to last line :.,$ s/money/Money/g from current line to last line

Page 12: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

12

Other useful vi commands

<< Shifts the current line to the left by one shift width.

>> Shifts the current line to the right by one shift width.

:set autoindent or :set ai. To unset it, you can type :set noautoindent or :set noai

:set nu :set nonu

Page 13: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

g77

=GNU Fortranthe Fortran development system for Project

GNU

GNUGNU's Not UNIXnon-profit organization

a free replacement for the UNIX f77replaced by gfortran since release 4.0

Page 14: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

GNU Compiler Collection (GCC)

GNU C CompilerCa replacement for the UNIX cc

→GNU Compiler Collection: C, C++, Fortran, Pascal, Java

cross-compiler

Page 15: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

gcc test.c./a.out

gcc test.c -o test ./test

-Wall警告訊息

gcc -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 test.c -o test 

Page 16: 1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date: 2011-07-19

16

Reference

$man ed

Mastering the VI editor

GNU Fortran 77 (g77) Legacy Site