EDITORS Lab 1 EECS 448 Dr. Fengjun Li and Meenakshi Mishra.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
Advertisements

 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
A Guide to Unix Using Linux Fourth Edition
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
CS 497C – Introduction to UNIX Lecture 17: - The GNU emacs Editor Chin-Chih Chang
Vi Editor TA for ITIS3100: Xu Fei
Linux+ Guide to Linux Certification, Second Edition
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
CS 497C – Introduction to UNIX Lecture 9: The vi/vim Editor Chin-Chih Chang
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
謝耀偉編著 國立高雄大學應用數學系 Living in Emacs DeveloperWorks, IBM.
Chapter 3 Mastering Editors
EMACS To quote the Emacs Manual: Emacs is the extensible, customizable, self- documenting real-time display editor. Emacs is an editor for plain-text,
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Productivity Programs Common Features and Commands.
1 © 2014 John Urrutia. All rights reserved. Chapter 7 The “ Emacs “ Editor.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
4 Editing files and Emacs Editing files The Emacs editor.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Introduction to Unix – CS 21 Lecture 7. Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage.
Text Editing February 2 nd, 2004 Class Meeting 3.
Chapter Three Text Editing1 System Programming Text Editing.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop III - Part A Shell Commands Professional Training.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
Learning Unix/Linux Based on slides from: Eric Bishop.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
CS:414 introduction to Unix and Linux
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Chapter 2 Basic vi Editor.
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
Presentation transcript:

EDITORS Lab 1 EECS 448 Dr. Fengjun Li and Meenakshi Mishra

Text Editors Writing program is similar to writing an essay in a specialized language Editors used to make writing as efficient as possible Editors for English should have preferably Spelling and Grammar check Copy, Cut and Paste Options Easy formatting options Manageable citations Reference tool Sectioning and Listing Text search and replacement

Editors in Programming Why do we need editors? Syntax highlighting and Code Formatting Syntax Reminders Debugging Line numbering Do not have your preferred document editor Preferred editor does not load Different working environment No Mouse Maintain Mobility without carrying your computer everywhere What do you expect to learn from this lab? Focus on two major text editors, vi and emacs Commands that will facilitate navigation and editing the text fast Focus on Command Line execution

Editors Which Editor shall I use? It depends on your preference and availability How do I remember so many commands? No one remembers all the commands Each one of us remembers the set of commands we use regularly and keep adding to the set Important objective is to get efficient and fast in programming Vi and Emacs are most popular as are entirely keyboard driven Mouse usually slows people down Other popular editors are gEdit, notepad, eclipse (it is an IDE)

Existing Editors Nano, Pico Default on Debian and Gentoo Distributions Text Editors (Notepad etc.) Vi, Vim, Gvim Available on all Unix/Linux Systems Can be installed on DOS, Windows and MacOS Vim (Vi Improved) has both text and GUI interface It is also extensively customizable Emacs Specifically designed with programmers in mind Has many useful features and plug-ins helpful for programmers Eclipse Powerful open source GUI IDE Similar to Microsoft Visual Studio We will be using this frequently

VI editor Standard editor Usually present in all Linux/UNIX systems Often the only editor you will have access to in machines newly installed or you cannot modify Uses very little resources Easy to use Commands are similar across boards

Open a file Create a directory Lab1 (mkdir Lab1) Go inside your newly created directory (cd Lab1) Open a new or existing file in edit mode(vi tryusingvi.txt) Open the file in read only mode (vi –R filename)

Modes Command Mode Used for administrative process e.g. saving, quitting Parse through text Cut, copy, paste Search and replace Anything typed is interpreted as command Insert Mode Can insert text into the file Anything typed is interpreted as input to the file and inserted Normal Mode Can provide some basic instructions like quitting, navigation

Modes Command Mode Enter command mode from normal mode Press ‘:’ or ‘/’ Exit command mode to normal mode Press esc or return Insert Mode Enter Insert mode from normal mode Press ‘i’ or ‘a’ Exit Insert mode to normal mode Press Esc

Try this In the file open, type “The quick brown fox jumped over the lazy dogs.” To type, you must first press ‘i’ to enter the insert mode Save it by typing ‘:w’ To give command, you must first enter normal mode by pressing esc Quit by typing ‘:q’ Open the file again (vi filename) Type something else in the file Quit without saving (:q!) Quit with saving (:wq)

Navigation and insertion Navigate through text (h/j/k/l  left/down/up/right) Scroll down one half page (ctrl-d) Scroll up one half page (ctrl-u) Scroll down one full page (ctrl-b) Scroll up one full page (ctrl-f) Move cursor to middle of page (M) Move cursor to top of the page (H) Move cursor to bottom of the page (L) Move cursor forward word at a time (w or 5w) Move cursor back word at a time (b or 5b) Move cursor to beginning of line/ end of line (0/$) Move cursor to beginning of sentence/ end of sentence ‘(‘ / ‘)’ Move cursor to matching bracket ‘%’

Editing Insert at the cursor (i) Append after the cursor (a) Undo last change (u) Undo all changes to entire line (U) Delete line (dd or 3dd) Delete contents of line after cursor (D) Delete word (dw) Delete character at cursor (x) Copy (yy or move cursor to the start position and press v, move cursor to end position and press y) Cut (v) Paste (P for before cursor and p for after the cursor)

Try This Open the file tryusingvi.txt Copy the sentence Paste the sentence multiple times Play around with the commands for navigation Move cursor up, down, left right Move page up, page down, half page up, half page down Move the cursor to middle of the page Play around with the commands for editing text Type another sentence of your choice Delete a word Delete the line Undo deletion

Other commands Search for search_seq (/search_seq or ?search_seq) Search and replace in current line (:s/search/replace/g) Search and replace in entire file (:%s/search/replace/g) Run linux commands (:!command)

Try This Play with the commands for searching and replacing Search for all the “The” in the text Change all the “The” to “A” Save this file See what other files are in your current directory

Emacs editor Started by Richard Stallman Free, portable, extensible Particularly good for programmers Modeless Only a small difference in GUI and SSH

Commands in Emacs All keys are commands Letters a-z and A-Z are commands to insert the letters on the file Every Command has a long name which you can look up in the documentation Examples are: kill-line, delete-backward-char, self-insert-command We will learn key-strokes which make editing fast Key combinations produce different commands 95 printable ASCII characters execute self-insert-command Ctrl-key (C-x) in combination with other keyboard keys constitute additional commands Meta-key (M-x) gives rise to fresh set of commands Usually ‘Alt’ key is the meta key Esc can also be used as meta key Esc is an ASCII character, so don’t hold it

Prefixes used C-c  Used for commands specific to particular modes C-h  Used for Help Commands C-x  Used for manipulating files, buffers and windows M-x  Type the full name of the command E.g. M-x compile C-u -N  Repeat the following command N times

Data Structures in Emacs File Actual file on disk Never edit this file directly Emacs reads a copy of the file in a buffer, and makes changes to buffer instead Saving file means writing copy of the buffer onto a file Buffer Internal data structure that holds the text you actually edit Can have any number of buffer active at any time Buffers have names The buffer has almost always the same name as the file it is visiting At any given time, only one buffer is selected Buffers can be deleted without effecting the files Window The view of the buffer Can split screens horizontally or vertically to view different buffers at once Windows can be created or deleted without effecting the buffer

Commands to Manipulate Files Open a file (emacs MyFirstJavaProgram.java or emacs) C-x C-f (find-file): Read a file When executed, emacs prompts you to enter filename Then it checks to see if file is still being edited If you are then it switches buffer Else creates a new buffer named same as the file, initialized with copy of the file C-x C-s (save-buffer): Save the file current buffer is in Write the current buffer to the file with same name C-x s (save-some-buffers): save all the buffers visiting file one by one Allows you to save all buffer visiting files, querying for each one C-x C-c: exit emacs C-g: Your best friend Exit the command

Movement Commands C-f, C-b: Move forward/backwards one character M-f, M-b: Move forward/backwards one word C-p, C-n: Move to previous/next line C-a, C-e: Move to beginning/end of line M-a, M-e: Move to beginning/end of sentence C-v (scroll-up) M-v (scroll-down)

Try This Open tryusingvi.txt Play around the movement commands Move up/down/left/right Move page up/ page down Move to previous line/ previous sentence/ next line/ next sentence

Commands to Manipulate Windows C-x o (other-window) C-x 0 (delete-window) C-x 1 (delete-other-windows) C-x 2 (split-window-vertically) C-x 3 (split-window-horizontally) C-M-v (scroll-other-window)

Commands to manipulate buffers C-x b (switch-to-buffer): Switches buffer of current window Prompts for a buffer name Switches buffer of current window to that buffer Creates a new empty buffer if you type a new name This buffer does not visit any file C-x C-b (list-buffers): Gives list of buffers Pops a new window that has the list C-x k (kill-buffer): Prompts for a buffer name Removes entire data-structure for that buffer Asks you if you want to save it first Does not delete file C-x C-q (vc-toggle-read-only): Make buffer read only or read-write only

Try This Download the java programs, MyFirstJavaProgram.java and MySecondJavaProgram.java from course website Open the two programs so that you can see both the programs and the text file you created On both programs, add a line to print your name at the beginning of the main function Split the screen and open the shell (M-x shell) See if the program is error free (M-x compile) Compile and Run the programs on shell See the list of buffers

Editing Command C-spc : Mark the starting of the text to be selected C-w: Kill the text from the mark to the cursor C-y: Paste the text recently killed C-s: Search forward Search for next match by typing C-s C-r: Search backward M-%: Replace C-g: Return to Start of Search M-u : make uppercase from cursor to end of word M-l : Make lowercase from cursor to end of word C-d: Delete character

Try This The contents of the MyFirstJavaProgram.java are just comments that will be printed Copy these comments and paste them on top of the main function of MySecondJavaProgram.java Make sure the program is error free Compile the program and run

Help Commands C-h m (describe-mode): Help page for current mode (C++, Python) C-h a (command-apropos): Prompts for a keyword, then lists all commands with that keyword C-h k (describe key): Prompts for a key-stroke and displays its description C-h i (info): Enters the Info hypertext document

Try This Obtain a list of all documents with the word “window” See if you find any commands you know Obtain the description related to key-stroke “C-x C-f”

Editor War Ref: en.wikipedia.org/wiki/Editor_war ViEmacs Keystroke ExecutionRetains each permutation of typed key creating path in the decision tree Emacs commands are key combination, so decision tree of commands formed but not of individual keystrokes Memory Usage and Customizability Vi: smaller, faster but not much customizable Vim: Evolved to provide more functionality and customization Longer to startup, requires more memory, highly customizable, has large number of features, an execution environment for a Lisp program designed for text-editing User EnvironmentOriginally used inside text-mode consoles Initially designed for text-mode console, but grew GUI very early Function/Navigation Interface Has distinct editing modeHas metakey chords KeyboardDoes not use Alt key, and rarely use Ctrl key Uses Alt, Ctrl and Shift keys for commands