0% found this document useful (0 votes)
124 views30 pages

Text Editors

The document discusses several common Linux text editors: - It describes vi, vim, emacs, and joe editors and explains their basic features and functions like cursor movement, text editing, and file management. - For each editor, it provides an overview of how to start the editor, common commands, and special features like syntax highlighting and spell checking. - It also discusses how to configure options in vi/vim through commands like set, map, and ab to customize their behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views30 pages

Text Editors

The document discusses several common Linux text editors: - It describes vi, vim, emacs, and joe editors and explains their basic features and functions like cursor movement, text editing, and file management. - For each editor, it provides an overview of how to start the editor, common commands, and special features like syntax highlighting and spell checking. - It also discusses how to configure options in vi/vim through commands like set, map, and ab to customize their behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Objectives

In this session, you will learn to:


Identify different types of text editors in Linux
Explain the vi text editor
Explain the vim text editor
Explain the emacs text editor
Explain the joe text editor

Identifying Different Types of Text Editors in Linux


An editor is application software, which is usually bundled
with an operating system.
A text editor is used to create and manage text files.
Linux has large number of available editors, many of them
inherited from Unix, such as emacs, vi, sed, and vim.

Features of an Editor
A text editor allows you to perform some of the following
basic functions:
Creating a file
Opening an existing file
Copying and pasting text
Searching text
Handling large amount of data

Editors Available with Linux


There are various editors available with Linux. Some of
them are:
Vi (visual editor)
Vim (visual editor improved)
Emacs (edit macros editor)
Sed (stream editor)
Ed (line editor)
Red (restricted ed editor)
Joe (joes own editor)
Rjoe (restricted joe editor)
Pico (pine composer)
Jstar (version of the joe editor compatible with WordStar)

Explaining the Vi Text Editor


The vi editor is a visual editor used for creating and editing
text files containing data, documents, or programs.
In Red Hat and Fedora distributions, vi is a symbolic link to
the vim editor.
You can work in the vi editor using various commands that
can be divided into the following categories:
Commonly used commands
Cursor movement commands
Advanced reading and saving commands
Insert and replace commands
Word movement commands
Deletion and modification commands
Commands to copy lines
Pattern-finding commands

Getting Started with Vi


The vi editor is invoked by giving the following command at
the Linux prompt:
vi filename

The vi editor works in the following two modes:


Command mode
Input mode

Commonly Used Commands


The following table lists some of the commonly used
commands in the vi editor.
Command
h

Action
Moves cursor to previous character.

Moves cursor to next character.

Moves cursor up one line.

Moves cursor down one line.

Deletes character at current cursor.

dd

Deletes line.

:wq+Enter

Saves all changes and quit.

:w+Enter

Saves the file.

:q!+Enter

Quits without saving changes.

:e <filename>+Enter

Opens the specified file.

:w <filename>+Enter

Writes to a different file.

:w! <filename>+Enter

Forces write to another file:!.

:! <command name>+Enter

Executes a shell command.

Cursor Movement Commands in Vi


The basic cursor movement commands are listed in the
following table.
Command

Action

Ctrl+d or D

Goes to the last line on the screen.

Ctrl+u or U

Scrolls up half screen.

Ctrl+F

Goes one page forward.

Ctrl+B

Goes one page backward.

nG

Goes to line number n.

0 (zero)

Goes to the beginning of the line.

Goes to the end of the line.

Goes to the first line on the screen.

Goes to the middle line on the screen.

Goes to the last line on the screen.

Z+Enter

Makes the current line the first line on the screen.

z-

Makes the current line the last line on the screen.

Advanced Reading and Savings Commands


The advanced reading and saving commands are listed in
the following table.
Command
:r file_name

Description
Enables you to read another file, file_name, into the current
file. The content of the file, file_name, is placed after the
cursor position in a new line.

:r !cmd_name

Enables you to read the output of the command, cmd_name,


into the current file. The output of the specified command is
placed after the cursor position in a new line.

:5,10w file_name

Saves lines 5 through 10 of the current file to the file,


file_name.
Appends lines 5 through 10 of the current file to the file,
file_name.
Saves lines starting from the current cursor position to the
end of the file in the file, file_name.

:5,10w >> file_name


:.,$w file_name
:n file_name

Enables you to edit a different file, file_name, which is other


than the current file, without exiting the vi editor.

:n#

Enables you to edit the previous file if multiple files are open.
This command enables you to toggle between two files.

Insert and Replace Commands


The insert and replace commands are listed in the following
table.
Command

Action

Appends after current character.

Appends at end of line.

Inserts before current character.

Inserts at beginning of line.

Inserts blank line below and allows insertion.

Inserts blank line above and allows insertion.

rx

Replaces current character with character x.

Rtext

Replaces characters with text (until Esc key is pressed). This


command takes you to the replace mode instead of the append
mode.

Word Movement Commands


The word movement commands are listed in the following
table.
Command

Action

Moves to next word.

Moves to previous word.

Moves to end of word.

Deletion and Modification Commands


The deletion and modification commands are listed in the
following table.
Command

Action

dw

Deletes word.

dd

Deletes line.

cw

Changes word.

cc

Changes line.

Deletes character before current cursor position.

Joins lines.

Undoes last change.

Restores last change.

.(dot)

Repeats last change.

Commands to Copy Lines


The commands to copy lines are listed in the following
table.
Command
p
P

Action
Places the yanked text after current cursor
position. This command is similar to the paste
operation in Windows.
Places the yanked text before the current
cursor position.

Pattern-finding Commands
The commands for pattern-finding are listed in the following
table.
Command

Action

fx

Finds the character x on the current line after current


cursor position.

Fx

Finds the character x on the current line before current


cursor position.

/pattern +Enter

Finds the next line containing the given pattern.

?pattern +Enter

Finds the previous line containing the pattern.

Configuring Vi
You can customize the way in which the vi or Vim editor
behaves.
You can use various escape mode commands to change
the behavior of the vi editor.
The three escape mode commands are:
set
map
ab (abbreviation)

The environment of the vi editor is defined by its variable


settings.
The set command is used to specify the values of the
environment variables of the vi editor environment.

Configuring Vi (Contd.)
The various options available with the set command are:
autoindent
ignorecase
magic
number
showmode
showmatch
tabstop=n
wrapscan

Configuring Vi (Contd.)
The map command is also used to customize the vi editor.
The syntax to use the map command is:
:map <the key, which needs mapping> <key
sequence which is to be mapped>

The two types of mapping commands are:


:map
map!

The ab command is another escape mode command that


enables you to define abbreviations for specific strings.
The syntax to use the ab command is:
:ab <string1> <string2>

Explaining the Vim Text Editor


Vim used to be called as vi Imitation. Since it is an improved
version of vi editor, its name is changed to vi improved.
Vim can edit any kind of ASCII text and is especially useful
for editing programs.

New Features of Vim


The new features that are introduced in vim are:
Language support
vimdiff
Editing a compressed file
Editing an archived file
Split windows
Syntax highlights
Last cursor position
Multiple undo/redo operations
Visual mode

Getting Started with Vim


To start the vim editor, you need to select
ApplicationSystem ToolsTerminal.
The following figure displays the opening screen of the vim
text editor.

Explaining the Emacs Text Editor


The emacs editor can format the source code for many
programming languages, such as C and C++.
You can work in the emacs editor using various commands
that can be divided into the following categories:
Commonly used commands
Deletion commands
Commands to copy lines
Commands useful for working with multiple files

Linux provides ispell utility to check the spelling of a word


and online help.

Getting Started with Emacs


The emacs editor is invoked by the following command from
the shell prompt:
emacs [command line switches] [file/s]

The following figure displays the opening screen of the


emacs editor.

Commonly Used Commands


The following table lists some of the commonly used
commands in the emacs editor.
Command
Ctrl+b
Ctrl+f
Ctrl+p
Ctrl+n
Ctrl+v
Alt+v
Ctrl+a
Ctrl+e
Ctrl+h
Ctrl+s
Ctrl+x+u
Ctrl+x Ctrl+c
Ctrl+x Ctrl+s
Ctrl+g

Action
Moves to the previous character.
Moves to the next character.
Moves up one line.
Moves down one line.
Moves to the next screen.
Moves to the previous screen.
Moves to the beginning of the line.
Moves to the end of the line.
Enters the emacs online Help.
Searches forward for a string.
Undoes the last edit.
Exits emacs.
Saves the file.
Cancels the current command.

Deletion Commands
The deletion commands are listed in the following table.
Command

Action

Ctrl+d

Deletes character.

Ctrl+k

Deletes line.

Commands to Copy Lines


The commands to copy lines are listed in the following table.
Command

Action

Ctrl+@

Marks text.

Ctrl+w

Cuts the selected text.

Ctrl+y

Pastes the text.

Working with Multiple Files


In emacs, you can work with multiple files at a time.
Some of the common commands used when working with
multiple files are listed in the following table.
Command
Ctrl+x Ctrl+f
Ctrl+x+b

Action
Loads a new file in the memory.
Switches between loaded files.

You can switch between the files that are open, and save or
close individual files.

Spell Check
You can also check the spelling of a word by using the
ispell utility of the emacs editor.
The following figure displays the screen from the spell
check option.

Online Help in Emacs


One of the best features of the emacs editor is that if you
ever get stuck, help is just a few keystrokes away.
The help option has many different topics.
Use the Ctrl+h+i keys to load the info documentation, and
read about the types of help available.

Explaining the Joe Text Editor


Another popular editor available is the joe editor. It is a
full-screen editor.
The following figure displays the joe editor.

Explaining the Joe Text Editor (Contd.)


The joe editor provides utilities, such as search and
replace.
The joe editor also provides spell check with ispell and
allows multiple files to be opened at a time.

You might also like