0% found this document useful (0 votes)
5 views

Chapter 8 Text Editing

Chapter 8 Text Editing

Uploaded by

abdikanipd
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chapter 8 Text Editing

Chapter 8 Text Editing

Uploaded by

abdikanipd
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

TEXT EDITORS

VIM
The name Vim is an acronym for Vi Improved. This editor is an
enhanced version of the Vi text.
Vim's common modes
The Vim editor has three modes that determine how the editor
functions: Normal (or Command), Insert, and GUI.
Normal mode
Normal mode allows you to give commands to the editor. Functions such as the following can be
found here:

 :w to write/save.
 :q to quit.
 :w <filename.txt> to name a new file.
 :q! to quit without saving the changes to the file

Press the Esc key to start the Normal mode and enter :(desired command) [Enter] to perform your
intended task. For example, if I was working in a new file and wanted to name it 'file.txt', I would
use the following:
INSERT MODE

 If you have made it this far, you probably know what the Insert mode
does. However, for those who don't, if you press the I key
(lowercase i) once you will see the "INSERT" prompt at the
bottom of the screen, indicating that you can now edit or add text.

 To exit this mode and return to Normal mode, press the Esc key once.
VI EDITOR

 A visual editor allows users to write and manipulate text in a file in a


Unix-based operating system. An improved version of Vi is called the
Vim editor. We can download Vim in Red Hat Enterprise Linux 8 (and
similar distributions) by using dnf install -y vim

 How do I use this editor?


#vi filename
BASIC COMMANDS

 I have written five basic commands that I use with vim:

 To copy text, use yy and yw:


 yy - Copies the current line.
 yw - Copies the current word from the character the lowercase w cursor is on, until
the end of the ….word.
 p - Pastes the copied text.
To search for a particular string in the file:
/ - For example, if you want to search for the string redhat in a given
file, you : :/redhat or red* to take you to the matching string.

To move forward and backward for one


fullscreen:

 Ctrl+f - moves forward by fullscreen.


 Ctrl+b - moves backward by fullscreen.
Intermediate Commands

I have written three advanced commands that I


use with the Vim editor:

TO UNDO AND DELETE A PARTICULAR LINE:

 u - Undo the previously executed command.

 dd - Deletes the current line of text.


The Essentials of Text Editing in
Linux

 Text editing skills using the command line are one of the most
crucial skills in Linux.

 In this section, you will learn how to use two popular text
editors in Linux: Vim and Nano.

 Suggesting that you master any one text editor of your


choice and stick to it.

 It will save you time and make you more productive. Vim and
nano are safe choices as they are present on most Linux
distributions.
Introduction to
Vim
 Vim is a popular text editing tool for the command line.

 it is powerful, customizable, and fast. Here are some reasons why you should
consider learning Vim.

 Most servers are accessed via a CLI.

 in system administration, you don't necessarily have the luxury of a GUI.

 But Vim has got your back – it'll always be there.

 Vim uses a keyboard-centric approach, as it is designed to be used without a


mouse, which can significantly speed up editing tasks once you have learned
the keyboard shortcuts.

 This also makes it faster than GUI tools


The Essentials of Text Editing in
Linux

 Some Linux utilities, for example editing cron jobs, work in the same
editing format as Vim.
 Vim is suitable for all – beginners and advanced users. Vim supports
complex string searches, highlighting searches, and much more.
 Through plugins, Vim provides extended capabilities to developers
and system admins that includes code completion, syntax
highlighting, file management, version control, and more.
 Vim has two variations: Vim (vim) and Vim tiny (vi). Vim tiny is a
smaller version of Vim that lacks some features of Vim.
Mastering movement and command modes
How to start using vim

vim your-file.txt
your-file.txt can either be a new file or an existing file that you want to
edit.
In the early days of the CLI, the keyboards didn't have arrow keys. Hence,
navigation was done using the set of available keys, hjkl being one of them.
Being keyboard-centric, using hjkl keys can greatly speed up text editing
tasks.
Note: Although arrow keys would work totally fine, you can still experiment
with hjkl keys to navigate. Some people find this this way of navigation
efficient.
💡Tip: To remember the hjkl sequence, use this: hang back, jump
down, kick up, leap forward.
The three Vim modes

 You need to know the 3 operating modes of Vim and how to switch between
them. Keystrokes behave differently in each command mode. The three
modes are as follows:
 Command mode.
 Edit mode.
 Visual mode.
 Command Mode. When you start Vim, you land in the command mode by
default. This mode allows you to access other modes.
 ⚠ To switch to other modes, you need to be present in the command mode
first
Edit Mode

 This mode allows you to make changes to


the file.
 To enter edit mode, press I while in
command mode.
 Note the '-- INSERT' switch at the end of
the screen.
Visual mode
 This mode allows you to work on a single character, a block of text,
or lines of text.

 Let's break it down into simple steps. Remember, use the below
combinations when in command mode.
 Shift + V → Select multiple lines.
 Ctrl + V → Block mode
 V → Character mode
 The visual mode comes in handy when you need to copy and paste
or edit lines in bulk.
Extended command mode.

The extended command mode allows you to perform


advanced operations like searching, setting line numbers,
and highlighting text.

We'll cover extended mode in the next section.

How to stay on track? If you forget your current mode, just


press ESC twice and you will be back in Command Mode.
Editing Efficiently in Vim: Copy/pasting and searching
2. How to search for text in Vim
Any series of strings can be searched with Vim
using the / in command mode. To search,
use /string-to-match.
In the command mode, type :set hls and
press enter. Search using /string-to-match. This will
highlight the searches.
Let's search a few strings:
3. How to exit Vim

First, move to command mode (by pressing escape


twice) and then use these flags:
 Exit without saving → :q!
 Exit and save → :wq!
Shortcuts in Vim: Making Editing Faster
Note: All these shortcuts work in the command
mode only.
Basic Navigation

 h: Move left
 j: Move down
 k: Move up
 l: Move right
 0: Move to the beginning of the line
 $: Move to the end of the line
 gg: Move to the beginning of the file
 G: Move to the end of the file
 Ctrl+d: Move half-page down
 Ctrl+u: Move half-page up
Editing

 i: Enter insert mode before the cursor


 I: Enter insert mode at the beginning of the line
 a: Enter insert mode after the cursor
 A: Enter insert mode at the end of the line
 o: Open a new line below the current line and enter insert mode
 O: Open a new line above the current line and enter insert mode
 x: Delete the character under the cursor
 dd: Delete the current line
 yy: Yank (copy) the current line (use this in visual mode)
 p: Paste below the cursor
 P: Paste above the cursor

You might also like