1

With Vim editor, before deleting lines or words, I'd like to view what I delete before committing a big mistake. Could anyone have an idea how could it possible to do that? Is there exist a command-line for that? If so, how could I do that?

2
  • 4
    You can use a visual selection (V) to highlight the text and delete the selection. Commented Dec 23, 2016 at 20:41
  • This is Vim. You can press u to undo. And if you have undofiles enabled, you can undo even if you save and quit. Commented Dec 25, 2016 at 4:54

2 Answers 2

2

As @ThomasDickey wrote there's a visual mode that you can enter by pressing v. This starts selection. After entering visual mode you can move the cursor around to select the extent of the text you want to delete. If you then press x it will delete everything selected, including the character under the cursor, and exit visual mode.

You can exit visual mode at any time by pressing Esc.

You can enter visual block mode by pressing Ctrl-v. This enables you to delete a rectangular block of text, or to insert (using Shift-i) into multiple lines at once.

0

If you're executing a global search and replace, such as

:%s/replaceme/withthis/g 

Then you may tag on a c (for "confirm"):

:%s/replaceme/withthis/gc 

This will ask for confirmation for each occurance of replaceme before carrying out the substitution.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.