SlideShare a Scribd company logo
1 of 34
Introduction to Linux (CS-110) Class
On
Editors in Linux
Dr. Poonam Panwar
Department of Computer Science and Engineering
Chitkara University, Punjab
Dr. Poonam Panwar 1
Why Editor
• An editor is just like a word processor without lot of features.
• All Os come with a basic text editor.
• Main use – writing something in plain text with no formatting so
another program can read it.
• Most popular text editor for Linux is called ‘Vi’. It is a program
that comes from UNIX.
• There is more recent version called ‘VIM’ which means ‘Vi
Mproved’.
• Problem with Vi/Vim – lot of people don’t like it, because of you
have to remember a lot of key combinations to do stuff that other
editors will do for you more easily.
Dr. Poonam Panwar 2
Types of Editor
• Mainly 3 types of editors.
1. console based editors
2. GUI based editors
3. Structure text editors
1. console based editors: it contains various editors like emacs, jed,
nano, pico, vim.
2. GUI based editors: gedit, gvim, Nedit, Tea, sublime.
3. Structure text editors: It refers to logically formatted and/or
annotated text to represent a data schema or programmatic
function.Two common formats available today are HTML for web
markup of text documents and XML for data representation.
HTML editors and XML editos
Dr. Poonam Panwar 3
Agenda
• Gedit
• Vi
• Vim
Dr. Poonam Panwar 4
Gedit Editor
• Gedit editor is the default editor for the GNOME desktop
environment. When we open a file, it will open with the Gedit
editor. It provides straightforward functionalities like any basic
text editor. It is a lightweight editor with a straight forward user
interface. It was publicly released in the year 2000 with a
GNOME desktop environment. It is developed using the C
programming language and supports all font family.
• It provides syntax highlighting.
• It supports internationalized text.
• It supports several programming languages.
Dr. Poonam Panwar 5
• To invoke gedit editor from terminal execute the following command from
terminal gedit Filename
Dr. Poonam Panwar 6
Explore gedit
Dr. Poonam Panwar 7
Multiple file in gedit
Dr. Poonam Panwar 8
Vi Editor
• The visual editor on the Linux.
• The vi editor comes with every version of Linux or Unix.
• Using vi is similar to using other editors in that you can see
your file on the screen ..
• The vi editor is the most popular editor in linux. The current
version is really "vim", but to invoke it simply type "vi".
• Before vi the primary editor used on Unix was the line editor
– User was able to see/edit only one line of the text at a time
• The vi editor is not a text formatter (like MS Word, Word
Perfect, etc.)
– you cannot set margins
– center headings
9
Dr. Poonam Panwar
Features of Vi
• The vi editor is:
A very powerful Editor.
It is required by all Linux Administrators to learn,
specially for Handling Linux Server.
It support navigation from point to point in the file,
and make changes.
Available on all UNIX/Linux systems.
10
Dr. Poonam Panwar
Opening a file in VI
• Type vi filename at the shell prompt
• After pressing enter the command prompt disappears and
you see tilde(~) characters on all the lines
• These tilde characters indicate that the line is blank
• Vi –R filename : It will open the file in readonly mode
• View filename : It will open the file in command mode
11
Dr. Poonam Panwar
vimtutor
Typing vimtutor launches a short but
very comprehensive tutorial for those
who want to learn their first vi
commands. This tutorial is a good
place to start learning vi.
Even though it provides only an
introduction and just seven lessons, it
has enough material to make you a
very proficient vi user, because it
covers a large number of commands.
After learning these basic ones, you
can look up new tricks to incorporate
into your list of vi commands because
there are always more optimal ways to
do things in vi with less typing.
Dr. Poonam Panwar 12
Mode in vi
Mode Feature
Command •By default, vi starts in Command mode.
•Each key is an editor command.
•Keyboard strokes are interpreted as commands that can modify file
contents.
Insert •Type i to switch to Insert mode from Command mode.
•Insert mode is used to enter (insert) text into a file.
•Insert mode is indicated by an “? INSERT ?” indicator at the bottom of
the screen.
•Press Esc to exit Insert mode and return to Command mode.
Line •Type : to switch to the Line mode from Command mode. Each key is an
external command, including operations such as writing the file contents
to disk or exiting.
•Uses line editing commands inherited from older line editors. Most of
these commands are actually no longer used. Some line editing
commands are very powerful.
•Press Esc to exit Line mode and return to Command mode.
13
Dr. Poonam Panwar
Command Mode
Dr. Poonam Panwar 14
Command Usage
vi myfile Start the vi editor and edit the myfile file
vi -r myfile Start vi and edit myfile in recovery mode from a system
crash
:r file2 Read in file2 and insert at current position
:w Write to the file
:w myfile Write out the file to myfile
:w! file2 Overwrite file2
:x or :wq Exit vi and write out modified file
:q Quit vi
:q! Quit vi even though modifications have not been saved
The table describes the most important commands used to start, exit, read, and
write files in vi. The ENTER key needs to be pressed after all of these commands
Navigation in Vi
• Moving Cursor Position
• You can move around only when you are in the command
mode
• Arrow keys usually works(but may not)
• The standard keys for moving cursor are:
h - for left
l - for right
j - for down
k - for up
w - to move one word forward
b - to move one word backward
15
Dr. Poonam Panwar
• Control-d scrolls the screen down (half screen)
• Control-u scrolls the screen up (half screen)
• Control-f scrolls the screen forward (full
screen)
• Control-b scrolls the screen backward (full
screen).
16
Dr. Poonam Panwar
All Navigation Options
Dr. Poonam Panwar 17
Key Usage
arrow keys To move up, down, left and right
j or <ret> To move one line down
k To move one line up
h or Backspace To move one character left
l or Space To move one character right
0 To move to beginning of line
$ To move to end of line
w To move to beginning of next word
:0 or 1G To move to beginning of file
:n or nG To move to line n
:$ or G To move to last line in file
CTRL-F or Page Down To move forward one page
CTRL-B or Page Up To move backward one page
^l To refresh and center screen
Working with Text in vi (Insert Mode)
Key Usage
a Append text after cursor; stop upon Escape key
A Append text at end of current line; stop upon Escape key
i Insert text before cursor; stop upon Escape key
I Insert text at beginning of current line; stop upon Escape key
o Start a new line below current line, insert text there; stop upon Escape key
O Start a new line above current line, insert text there; stop upon Escape key
r Replace character at current position
R Replace text starting with current position; stop upon Escape key
Dr. Poonam Panwar 18
Delete in Vi
• x - deletes the current character
• d - is the delete command but pressing only d will not delete
anything you need to press a second key
– dw - deletes to end of word
– dd - deletes the current line
– d0 - deletes to beginning of line
• There are many more keys to be used with delete command
• The vi commands can be used followed by a number such as
n<command key(s)>
– For example dd deletes a line 5dd will delete five lines.
19
Dr. Poonam Panwar
Delete Options
x Delete character at current position
Nx Delete N characters, starting at current
position
dw Delete the word at the current position
D Delete the rest of the current line
dd Delete the current line
Ndd or dNd Delete N lines
u Undo the previous operation
yy Yank (copy) the current line and put it in
buffer
Nyy or yNy Yank (copy) N lines and put it in buffer
p Paste at the current position the yanked
line or lines from the buffer.
Dr. Poonam Panwar 20
Yank and paste
• yy - (yank) copy current line to buffer
• nyy - Where n is number of lines
• p - Paste the yanked lines from buffer to the
line below
• P - Paste the yanked lines from buffer to the
line above
21
Dr. Poonam Panwar
Searching for Text in vi
The table describes the most important commands used when searching for text in vi.
The ENTER key should be pressed after typing the search pattern.
Dr. Poonam Panwar 22
Command Usage
/pattern Search forward for pattern
?pattern Search backward for pattern
The table describes the most important keystrokes used when searching for text in vi.
Key Usage
n Move to next occurrence of search pattern
N Move to previous occurrence of search
pattern
Exit from vi
• :q <enter> is to exit, if you have not made any
changes to the file
• :q! <enter> is the forced quit, it will discard the
changes and quit
• :wq <enter> is for save and Exit
• :x <enter> is same as above command
• ZZ is for save and Exit (Note this command is
uppercase)
• The ! Character forces over writes, etc. :wq!
23
Dr. Poonam Panwar
Using External Commands in Vi
• Typing : sh command opens an
external command shell. When
you exit the shell, you will resume
your vi editing session.
• Typing :!executes a command
from within vi. The command
follows the exclamation point.
This technique is best suited for
non-interactive commands, such
as : ! wc %. Typing this will run
the wc (word count) command on
the file; the
character % represents the file
currently being edited.
Dr. Poonam Panwar 24
Vim
• Vim is an advanced and highly configurable text editor built to
enable efficient text editing. Vim text editor is developed by Bram
Moolenaar. It supports most file types and vim editor is also known
as a programmer’s editor. We can use with its plugin based on our
needs.
• If we try to open a file in vim then type a command vim filename
then you will have the following output
25
Dr. Poonam Panwar
• To install vim on Debian based Linux like ubuntu run the command:
sudo apt install vim
• To create a file in vim type command vim filename
• To write data in a file we need to go in insert mode. To go into the
insert mode we have to type i. You will see the insert mode at the
bottom of the file
26
Dr. Poonam Panwar
• We have written the data into a file now the task is to save and close
the file to do that first exit from insert mode by pressing the Esc key.
To write a command first type semicolon ( : ) and then type the
command wq! And then hit ENTER.
• Vim also comes with its own tutorial. You can see this tutorial by
command vimtutor into the terminal .
27
Dr. Poonam Panwar
Command Mode
• Command mode
– Chosen automatically when starting vim
• Advanced navigational commands in vim
28
Dr. Poonam Panwar
Command mode
29
Dr. Poonam Panwar
Insert Mode
• Must be in insert mode to type text
• Change to insert mode with one of the commands
• vim editor displays -- INSERT -- at the lower left to indicate insert
mode
• Press the Esc key to change back to command mode
30
Dr. Poonam Panwar
Text Modification in Vim
• Modify text using the keyboard instead of the mouse
• Commands for modifying text in vim in command mode
31
Dr. Poonam Panwar
Modifying Text in Insert mode
• Modify text using the keyboard instead of the mouse
• Commands for modifying text in vim in insert mode
32
Dr. Poonam Panwar
Cut, Yank, and Paste
• Cut text : Store text in a buffer
• Paste text: Move from buffer to cursor location
• Yank (copy) text: Keep in current location and copy to buffer
33
Dr. Poonam Panwar
THANK YOU
Dr. Poonam Panwar 34

More Related Content

Similar to lectuer 21-22.pptx

Similar to lectuer 21-22.pptx (20)

Introduction to vi editor
Introduction to vi editorIntroduction to vi editor
Introduction to vi editor
 
Basic linux day 4
Basic linux day 4Basic linux day 4
Basic linux day 4
 
Tuffarsi in vim
Tuffarsi in vimTuffarsi in vim
Tuffarsi in vim
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editor
 
VI editor in unix
VI editor in unix VI editor in unix
VI editor in unix
 
Vi editor Linux Editors
Vi editor Linux EditorsVi editor Linux Editors
Vi editor Linux Editors
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Presentacion vim
Presentacion vimPresentacion vim
Presentacion vim
 
Vi and redirection & piping in linux
Vi and redirection & piping in linuxVi and redirection & piping in linux
Vi and redirection & piping in linux
 
Vi Editor
Vi EditorVi Editor
Vi Editor
 
Unit 5 vim an advanced text editor
Unit 5 vim an advanced text editorUnit 5 vim an advanced text editor
Unit 5 vim an advanced text editor
 
Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)
 
Vi editor
Vi   editorVi   editor
Vi editor
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
Using Vi Editor.pptx
Using Vi Editor.pptxUsing Vi Editor.pptx
Using Vi Editor.pptx
 
Using Vi Editor.pptx
Using Vi Editor.pptxUsing Vi Editor.pptx
Using Vi Editor.pptx
 
Vi editor
Vi editorVi editor
Vi editor
 
Vim Basics
Vim BasicsVim Basics
Vim Basics
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim Introduction
 
andrew's guide to vim
andrew's guide to vimandrew's guide to vim
andrew's guide to vim
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

lectuer 21-22.pptx

  • 1. Introduction to Linux (CS-110) Class On Editors in Linux Dr. Poonam Panwar Department of Computer Science and Engineering Chitkara University, Punjab Dr. Poonam Panwar 1
  • 2. Why Editor • An editor is just like a word processor without lot of features. • All Os come with a basic text editor. • Main use – writing something in plain text with no formatting so another program can read it. • Most popular text editor for Linux is called ‘Vi’. It is a program that comes from UNIX. • There is more recent version called ‘VIM’ which means ‘Vi Mproved’. • Problem with Vi/Vim – lot of people don’t like it, because of you have to remember a lot of key combinations to do stuff that other editors will do for you more easily. Dr. Poonam Panwar 2
  • 3. Types of Editor • Mainly 3 types of editors. 1. console based editors 2. GUI based editors 3. Structure text editors 1. console based editors: it contains various editors like emacs, jed, nano, pico, vim. 2. GUI based editors: gedit, gvim, Nedit, Tea, sublime. 3. Structure text editors: It refers to logically formatted and/or annotated text to represent a data schema or programmatic function.Two common formats available today are HTML for web markup of text documents and XML for data representation. HTML editors and XML editos Dr. Poonam Panwar 3
  • 4. Agenda • Gedit • Vi • Vim Dr. Poonam Panwar 4
  • 5. Gedit Editor • Gedit editor is the default editor for the GNOME desktop environment. When we open a file, it will open with the Gedit editor. It provides straightforward functionalities like any basic text editor. It is a lightweight editor with a straight forward user interface. It was publicly released in the year 2000 with a GNOME desktop environment. It is developed using the C programming language and supports all font family. • It provides syntax highlighting. • It supports internationalized text. • It supports several programming languages. Dr. Poonam Panwar 5
  • 6. • To invoke gedit editor from terminal execute the following command from terminal gedit Filename Dr. Poonam Panwar 6
  • 8. Multiple file in gedit Dr. Poonam Panwar 8
  • 9. Vi Editor • The visual editor on the Linux. • The vi editor comes with every version of Linux or Unix. • Using vi is similar to using other editors in that you can see your file on the screen .. • The vi editor is the most popular editor in linux. The current version is really "vim", but to invoke it simply type "vi". • Before vi the primary editor used on Unix was the line editor – User was able to see/edit only one line of the text at a time • The vi editor is not a text formatter (like MS Word, Word Perfect, etc.) – you cannot set margins – center headings 9 Dr. Poonam Panwar
  • 10. Features of Vi • The vi editor is: A very powerful Editor. It is required by all Linux Administrators to learn, specially for Handling Linux Server. It support navigation from point to point in the file, and make changes. Available on all UNIX/Linux systems. 10 Dr. Poonam Panwar
  • 11. Opening a file in VI • Type vi filename at the shell prompt • After pressing enter the command prompt disappears and you see tilde(~) characters on all the lines • These tilde characters indicate that the line is blank • Vi –R filename : It will open the file in readonly mode • View filename : It will open the file in command mode 11 Dr. Poonam Panwar
  • 12. vimtutor Typing vimtutor launches a short but very comprehensive tutorial for those who want to learn their first vi commands. This tutorial is a good place to start learning vi. Even though it provides only an introduction and just seven lessons, it has enough material to make you a very proficient vi user, because it covers a large number of commands. After learning these basic ones, you can look up new tricks to incorporate into your list of vi commands because there are always more optimal ways to do things in vi with less typing. Dr. Poonam Panwar 12
  • 13. Mode in vi Mode Feature Command •By default, vi starts in Command mode. •Each key is an editor command. •Keyboard strokes are interpreted as commands that can modify file contents. Insert •Type i to switch to Insert mode from Command mode. •Insert mode is used to enter (insert) text into a file. •Insert mode is indicated by an “? INSERT ?” indicator at the bottom of the screen. •Press Esc to exit Insert mode and return to Command mode. Line •Type : to switch to the Line mode from Command mode. Each key is an external command, including operations such as writing the file contents to disk or exiting. •Uses line editing commands inherited from older line editors. Most of these commands are actually no longer used. Some line editing commands are very powerful. •Press Esc to exit Line mode and return to Command mode. 13 Dr. Poonam Panwar
  • 14. Command Mode Dr. Poonam Panwar 14 Command Usage vi myfile Start the vi editor and edit the myfile file vi -r myfile Start vi and edit myfile in recovery mode from a system crash :r file2 Read in file2 and insert at current position :w Write to the file :w myfile Write out the file to myfile :w! file2 Overwrite file2 :x or :wq Exit vi and write out modified file :q Quit vi :q! Quit vi even though modifications have not been saved The table describes the most important commands used to start, exit, read, and write files in vi. The ENTER key needs to be pressed after all of these commands
  • 15. Navigation in Vi • Moving Cursor Position • You can move around only when you are in the command mode • Arrow keys usually works(but may not) • The standard keys for moving cursor are: h - for left l - for right j - for down k - for up w - to move one word forward b - to move one word backward 15 Dr. Poonam Panwar
  • 16. • Control-d scrolls the screen down (half screen) • Control-u scrolls the screen up (half screen) • Control-f scrolls the screen forward (full screen) • Control-b scrolls the screen backward (full screen). 16 Dr. Poonam Panwar
  • 17. All Navigation Options Dr. Poonam Panwar 17 Key Usage arrow keys To move up, down, left and right j or <ret> To move one line down k To move one line up h or Backspace To move one character left l or Space To move one character right 0 To move to beginning of line $ To move to end of line w To move to beginning of next word :0 or 1G To move to beginning of file :n or nG To move to line n :$ or G To move to last line in file CTRL-F or Page Down To move forward one page CTRL-B or Page Up To move backward one page ^l To refresh and center screen
  • 18. Working with Text in vi (Insert Mode) Key Usage a Append text after cursor; stop upon Escape key A Append text at end of current line; stop upon Escape key i Insert text before cursor; stop upon Escape key I Insert text at beginning of current line; stop upon Escape key o Start a new line below current line, insert text there; stop upon Escape key O Start a new line above current line, insert text there; stop upon Escape key r Replace character at current position R Replace text starting with current position; stop upon Escape key Dr. Poonam Panwar 18
  • 19. Delete in Vi • x - deletes the current character • d - is the delete command but pressing only d will not delete anything you need to press a second key – dw - deletes to end of word – dd - deletes the current line – d0 - deletes to beginning of line • There are many more keys to be used with delete command • The vi commands can be used followed by a number such as n<command key(s)> – For example dd deletes a line 5dd will delete five lines. 19 Dr. Poonam Panwar
  • 20. Delete Options x Delete character at current position Nx Delete N characters, starting at current position dw Delete the word at the current position D Delete the rest of the current line dd Delete the current line Ndd or dNd Delete N lines u Undo the previous operation yy Yank (copy) the current line and put it in buffer Nyy or yNy Yank (copy) N lines and put it in buffer p Paste at the current position the yanked line or lines from the buffer. Dr. Poonam Panwar 20
  • 21. Yank and paste • yy - (yank) copy current line to buffer • nyy - Where n is number of lines • p - Paste the yanked lines from buffer to the line below • P - Paste the yanked lines from buffer to the line above 21 Dr. Poonam Panwar
  • 22. Searching for Text in vi The table describes the most important commands used when searching for text in vi. The ENTER key should be pressed after typing the search pattern. Dr. Poonam Panwar 22 Command Usage /pattern Search forward for pattern ?pattern Search backward for pattern The table describes the most important keystrokes used when searching for text in vi. Key Usage n Move to next occurrence of search pattern N Move to previous occurrence of search pattern
  • 23. Exit from vi • :q <enter> is to exit, if you have not made any changes to the file • :q! <enter> is the forced quit, it will discard the changes and quit • :wq <enter> is for save and Exit • :x <enter> is same as above command • ZZ is for save and Exit (Note this command is uppercase) • The ! Character forces over writes, etc. :wq! 23 Dr. Poonam Panwar
  • 24. Using External Commands in Vi • Typing : sh command opens an external command shell. When you exit the shell, you will resume your vi editing session. • Typing :!executes a command from within vi. The command follows the exclamation point. This technique is best suited for non-interactive commands, such as : ! wc %. Typing this will run the wc (word count) command on the file; the character % represents the file currently being edited. Dr. Poonam Panwar 24
  • 25. Vim • Vim is an advanced and highly configurable text editor built to enable efficient text editing. Vim text editor is developed by Bram Moolenaar. It supports most file types and vim editor is also known as a programmer’s editor. We can use with its plugin based on our needs. • If we try to open a file in vim then type a command vim filename then you will have the following output 25 Dr. Poonam Panwar
  • 26. • To install vim on Debian based Linux like ubuntu run the command: sudo apt install vim • To create a file in vim type command vim filename • To write data in a file we need to go in insert mode. To go into the insert mode we have to type i. You will see the insert mode at the bottom of the file 26 Dr. Poonam Panwar
  • 27. • We have written the data into a file now the task is to save and close the file to do that first exit from insert mode by pressing the Esc key. To write a command first type semicolon ( : ) and then type the command wq! And then hit ENTER. • Vim also comes with its own tutorial. You can see this tutorial by command vimtutor into the terminal . 27 Dr. Poonam Panwar
  • 28. Command Mode • Command mode – Chosen automatically when starting vim • Advanced navigational commands in vim 28 Dr. Poonam Panwar
  • 30. Insert Mode • Must be in insert mode to type text • Change to insert mode with one of the commands • vim editor displays -- INSERT -- at the lower left to indicate insert mode • Press the Esc key to change back to command mode 30 Dr. Poonam Panwar
  • 31. Text Modification in Vim • Modify text using the keyboard instead of the mouse • Commands for modifying text in vim in command mode 31 Dr. Poonam Panwar
  • 32. Modifying Text in Insert mode • Modify text using the keyboard instead of the mouse • Commands for modifying text in vim in insert mode 32 Dr. Poonam Panwar
  • 33. Cut, Yank, and Paste • Cut text : Store text in a buffer • Paste text: Move from buffer to cursor location • Yank (copy) text: Keep in current location and copy to buffer 33 Dr. Poonam Panwar
  • 34. THANK YOU Dr. Poonam Panwar 34