MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
January
Sun Mon Tue Wed Thu Fri Sat
13
       
2017
Months
Jan


Fri, Jan 13, 2017 10:27 pm

Deleting up to a word or back to a word in the Vi or Vim editor

In the vi or Vim text editor, you can delete all characters on a line up to a specified word by placing the cursor on the line at the point where you wish to start the deletion then hit the d key followed by the slash key followed by the word up to which you wish to remove the characters on the line. E.g., suppose you have the following line:

If you can force your heart and nerve and sinew To serve your turn long after they are gone, And so hold on when there is nothing in you Except the Will which says to them: “Hold on”;

From the poem If— by Rudyard Kipling (1865-1936)

If you wished to delete all of the text on the line from the word "To" up until, but not including the word "And" in "And so hold on...", while in command mode, not insert mode, you could move the cursor to the "T" in "To" and then hit the d key followed by the forward slash key (/) and then type And (make sure you use the matching capitalization). The line would then appear as shown below.

If you can force your heart and nerve and sinew And so hold on when there is nothing in you Except the Will which says to them: “Hold on”;

Suppose, instead, you had the cursor at the word "To" as before, but wanted to delete backwards through the word "If", i.e., all the way to the beginning of the line, instead. You could then hit the d key while in command mode, then hit the question mark (?) key and type If. You would then have the text below.

To serve your turn long after they are gone, And so hold on when there is nothing in you Except the Will which says to them: “Hold on”;

For the backwards deletion, the word you type after the question mark is included in the deletion. In this case, if you wished to delete backwards to the beginning of the line, you could also have hit the d key followed by the ? key and then hit the caret (^) key, which represents the beginning of the line. Likewise, you could hit the dollar sign ($) key to delete forward to the end of the line, which it represents, or you could just hit the D key, instead of the lower-case "d" to delete from the current cursor position to the end of the line.

[/software/editors/vi] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo