Guide: Delete Lines in VI: Tips and Tutorial

vi is a well-known screen-oriented text editor dating back to the early days of Unix. It is the most impressive feature is that it can work in two different modes. In insert mode, the text becomes part of the file. In normal mode, keystrokes are treated as direct commands. Therefore, various keyboard commands are used to reduce the amount of work required to edit a file. But when the commands are so different, is it really easier to delete lines or edit them with the keystroke commands? – Let’s figure it out.

Cut a line or block

Now if you want to paste that line elsewhere, move the cursor to the new location and press p. Note that pressing p pastes the line or block after the cursor position. If you want to paste before the cursor position, you must press P.

Edit across a line

You can also change the selected text by pressing c in step 6. Pressing d cuts off, pressing y makes jerks or copies, and c opens insert mode where you can add new text. This can help you replace an entire line or block without having to cut them first.

Delete multiple lines

There are two good options if you want to delete more than one line in vi. “:% D” This command will delete all lines. The ‘:’ puts vi in ​​command mode. The ‘%’ character tells it to apply the ‘d’ (delete command) to all lines. “: 1, $ d” This is the more popular alternative. Again, the ‘:’ introduces a command. “1, $” tells vi which lines to target. In this example, it would be the lines starting with line 1 and the last. ‘d’ stands for delete. But what makes this assignment better than the first? – This one is customizable. You can use it to delete rules in bulk, but without having to delete them all. If you use something like “: 4, $ – 2d”, vi will delete all lines between the third and second to last line. It leaves the first three intact because the lines start with 1 and not 0. And you specify the first line you want to delete, in this example 4. The ‘-2’ basically indicates how many lines start from the last and count down to 1.

Using characters, Word, and lines in normal mode

First, you need to make sure to press Escape to enter normal mode. After that, you can use the following vi commands to delete specific information.

dd

This command will delete an entire line. You can place the cursor anywhere on the line, be it on a word or on an empty space. The rule and all the space it occupied are cleared.

x / X

If you want to remove just one character from a line, you can use x. Place the cursor after a character and press x. This removes the character and also the space it took up. This also means that all the other characters in the vicinity come together to fill the gap. You can also use x to delete an empty space in a line. If you hover over a character and want to delete the character before it, press X instead of x.

dw

If you press dw while your cursor is at the beginning of a word, that word is deleted. This also removes the space occupied by the word. You can also delete only parts of a word. Place your cursor to the left of the section you want to delete. Press dw to delete those characters and the space they occupied in the line. Keep in mind that doing this will bring the adjacent characters together to fill the gap.

A Final Thought

As interesting and unique as vi is as a modal editor, it takes a while to get used to. There is very little feedback when it comes to switching modes. This makes it very easy to accidentally enter code text when you should issue a command, and vice versa.

Delete Lines in VI: Tips and Tutorial: benefits

Faq

Final note

I hope you like the guide Delete Lines in VI: Tips and Tutorial. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends. For our visitors: If you have any queries regards the Delete Lines in VI: Tips and Tutorial, then please ask us through the comment section below or directly contact us. Education: This guide or tutorial is just for educational purposes. Misinformation: If you want to correct any misinformation about the guide “Delete Lines in VI: Tips and Tutorial”, then kindly contact us. Want to add an alternate method: If anyone wants to add more methods to the guide Delete Lines in VI: Tips and Tutorial, then kindly contact us. Our Contact: Kindly use our contact page regards any help. You may also use our social and accounts by following us on Whatsapp, Facebook, and Twitter for your questions. We always love to help you. We answer your questions within 24-48 hours (Weekend off). Channel: If you want the latest software updates and discussion about any software in your pocket, then here is our Telegram channel.

Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 69Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 34Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 99Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 19Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 38Delete Lines in VI  Tips and Tutorial  2022    Compsmag - 65