![]() |
In this article, we will cover how to delete multiple lines in the vi editor we will look into the different methods to achieve it. First, we look at what Linux and VI editors are and why we use them, what are its features and how can we use them, followed by a basic guide for the editor and different methods to delete multiple lines in the vi editor. LinuxLinux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of the popular Linux distributions are Ubuntu, Cent OS, Red Hat, Debian, and Kali Linux. VI EditorVi Editor is a widely used text editor in Unix/Linux systems and is known for its efficiency and flexibility. Vi editor was developed in 1976 by Bill Joy and later in 1991, an improved version of Vi editor was released which is known as VI IMproved (VIM). There are two modes in Vi Editor:
Basic Vi Editor Guide1. Create/Edit a file using Vi editor vi filename 2. Insert Mode To make any changes in the file first, you need to enter the insert mode to modify the file. To get into insert mode press the button ‘i’ to enter in insert mode. 3. Command Mode To run any command in the vi editor you have to first enter the command mode if you are currently in the insert mode then press Esc and then ‘:’ colon followed by your command to run your command in the editor. 4. Navigation in the editor
Delete a Single LineTo delete a single line follow the below steps:
Delete multiple lines in vi editorTo delete multiple lines Press Esc to leave the insert/editing mode, enter the number of lines you want to delete followed by ‘dd’ i.e. ndd and the editor will delete the mentioned number of lines from the current line. Example: 3dd – Three lines including the current line got deleted. Delete a range of linesTo delete a range of lines follow the below steps:
Example: :3,10d in this command the editor will delete the lines from 3 to 10 including the extremes. Example Screenshot: You can also add wildcard characters in commands mentioned below:
Examples:
Delete lines that contain a specific patternTo delete lines based on a pattern using regular expression we use g command here g stands for global, syntax of commands is as follows:
Example:
To delete all the lines that starts with a particular character:
Examples:
To delete all the lines that are empty:
Example: ConclusionIn this article, we had covered a basic vi editor guide, followed by command to delete a single line and it’s example followed by commands to delete multiple line based on constraints like deleting multiple line in a given range, deleting multiple lines based on pattern along with examples and we also discussed wildcard characters to optimise the commands. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |