Pattern matching with the vi editor

For learning pattern matching, we will ensure that the pattern that we will search should be highlighted when the searched pattern is found.

The configuration file for vi is /etc/vimrc.

In the vi editor, give the following command to highlight search:

Sr.

Commands

Description

1

:set hlsearch

This highlights search pattern

2

:se[t] showmode

Show when you are in insert mode

3

:se[t] ic

Ignore case when searching

4

:set noic

Shows case sensitive search

The mentioned user should open the file in vi, press the Esc button so that it goes into command mode and then enter colon followed by these commands.

The following are commands for pattern search and replace:

Sr.

Commands

Description

1

Get Learning Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.