Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI The UNIX System Editing files

Similar presentations


Presentation on theme: "CSCI The UNIX System Editing files"— Presentation transcript:

1 CSCI 330 - The UNIX System Editing files
EDITORS iN LINUX Editing files NIU - Department of Computer Science

2 Editor features enter text search and replace copy, cut and paste
undo and redo importing and exporting text save and cancel CSCI The UNIX System 3

3 Text files Unix file name does not require file extension
Unix file system does not consider the extension when treating files However, some extensions are commonly used Program source code: .c .cc .cpp .f .f77 .f95 Compiled object code: .o .a .so .sa Compressed files: .z .gz .zip Archive files: .tar .tz Web site source code: .html .shtml .php Executable files typically have no extension Text files that will be moved to Windows: .txt CSCI The UNIX System

4 Unix Text editors vim emacs pico nano GUI editors mousepad xedit
CSCI The UNIX System

5 The vi Editor short for: visual editor available on all UNIX systems
original vi part of BSD Unix written by Bill Joy in 1976 many derived, improved versions available open source vim (vi improved) is part of GNU/Linux vi has multiple modes of operation: input mode, command mode, last-line mode CSCI The UNIX System

6 vi Editing modes : Command Mode Esc Input Mode Insert (i, I)
CSCI The UNIX System vi Editing modes Command Mode Esc Input Mode CSCI The UNIX System Insert (i, I) Append (a, A), Open (o, O) Change (c), Replace (r, R) : Return Last-Line Mode NIU - Department of Computer Science

7 VIM TUTORIAL Online tutorial: vimtutor
UNIX Text Editors VIM TUTORIAL Online tutorial: vimtutor Never start something you can’t exit To end vi tutorial in the middle of the session, execute the command :q! :q! = quit without saving :wq = write out (save) and quit F1 = help or :help :help <command> :q to exit help window CSCI The UNIX System 8 Copyright Department of Computer Science, Northern Illinois University, 2004 8

8 COMMANDS Delete characters Insert characters
UNIX Text Editors COMMANDS Delete characters x deletes character under the cursor Insert characters i converts to insert mode then type characters <esc> to exit insert mode CSCI The UNIX System 9 Copyright Department of Computer Science, Northern Illinois University, 2004 9

9 COMMANDS Insert lines Append characters o = open line below cursor
UNIX Text Editors COMMANDS Insert lines o = open line below cursor O = open line above cursor <esc> to exit insert mode Append characters A converts to insert mode at end of a line then type characters CSCI The UNIX System 10 Copyright Department of Computer Science, Northern Illinois University, 2004 10

10 COMMANDS Deletion Using motions for movement d$ deletes to end of line
UNIX Text Editors COMMANDS Deletion d$ deletes to end of line dw deletes to beginning of next word de deletes to end of current word d + motion Using motions for movement Use any of the motions above Use count for repetition 2w = move cursor two words forward 0 = start of line CSCI The UNIX System 11 Copyright Department of Computer Science, Northern Illinois University, 2004 11

11 COMMANDS Using repetition as part of deletion Deleting a line Undo
UNIX Text Editors COMMANDS Using repetition as part of deletion 2dw deletes next two words Deleting a line dd = delete line 2dd = delete two lines Undo u = undo one command U = restore a line cntl-R = redo a command CSCI The UNIX System 12 Copyright Department of Computer Science, Northern Illinois University, 2004 12

12 COMMANDS p = put back the deleted text (in new place)
UNIX Text Editors COMMANDS p = put back the deleted text (in new place) one of the delete command above + put = cut-and-paste More general cut-and-paste v = start visual mode (start block) move cursor to end of block y = yank (copy to buffer) then p = put in new place CSCI The UNIX System 13 Copyright Department of Computer Science, Northern Illinois University, 2004 13

13 COMMANDS Location ctrl-g = show position in file
UNIX Text Editors COMMANDS Location ctrl-g = show position in file G = go to bottom of file gg = go to top of file <number>G = go to line <number> CSCI The UNIX System 14 Copyright Department of Computer Science, Northern Illinois University, 2004 14

14 COMMANDS Search Search for matching parentheses
UNIX Text Editors COMMANDS Search /<phrase> = search /<phrase>\c = ignore case ?<phrase> = search backwards n = repeat search N = repeat search in the other direction cntl-o = move backward one instance cntl-i = move forward one instance Search for matching parentheses Put cursor on (, [ or { % = go to matching one % = go to first one again CSCI The UNIX System 15 Copyright Department of Computer Science, Northern Illinois University, 2004 15

15 COMMANDS Substitute (replace) :s/thee/the = changes first one
UNIX Text Editors COMMANDS Substitute (replace) :s/thee/the = changes first one :s/thee/the/g = changes all (global change) :s/thee/the/gc = change all with query :#,#/thee/the/g = only change within that line range CSCI The UNIX System 16 Copyright Department of Computer Science, Northern Illinois University, 2004 16

16 COMMANDS Files :w filename = write a file (save) :!ls = list directory
UNIX Text Editors COMMANDS Files :w filename = write a file (save) :!ls = list directory :!xx = any command CSCI The UNIX System 17 Copyright Department of Computer Science, Northern Illinois University, 2004 17

17 SETTING OPTIONS Options for search :noic, etc. = turn it off
UNIX Text Editors SETTING OPTIONS Options for search :set ic = ignore case :set hlsearch = highlight matches :set icsearch = incremental search :noic, etc. = turn it off Make permanent by putting in ./.vimrc CSCI The UNIX System 18 Copyright Department of Computer Science, Northern Illinois University, 2004 18

18 The emacs editor originally started as editor macros in 1976
Gosling Emacs available for Unix in 1981 GNU Emacs created by Richard Stallman in 1984 very popular editor on Unix until recently history: editor war: emacs vs. vi uses lisp-like macro language for powerful features and extensions: programming language sensitive editing client news reader has built-in tutorial: ^h-t CSCI The UNIX System

19 THE PICO AND NANO EDITORS
part of the popular pine mail utility on UNIX developed by the University of Washington pico = pine composer nano is improved open source of pico available for GNU/Linux very intuitive operation on-screen guide and help CSCI The UNIX System

20 GUI Editors use onscreen direct manipulation via mouse and menus
emacs xedit mousepad require to run X11 window server CSCI The UNIX System


Download ppt "CSCI The UNIX System Editing files"

Similar presentations


Ads by Google