0

Is it possible to select all the text and delete it it in vi other than hitting backspace?

2
  • By pressing "d"?
    – Heptite
    Nov 29, 2022 at 14:52
  • 2
    if you want to delete it anyhow, just use :%d Nov 29, 2022 at 14:55

2 Answers 2

3

To delete text, use the d operator. This can be done from visual mode, but is normally done with a motion or text object, such as

  • daw delete a word
  • d} delete to end of paragraph
  • dd delete a line

There is also a line-wise Ex command :delete. Coupled with the range % "all lines", :%delete deletes everything in a buffer.

1
  • I didn't know about %delete. Thanks for sharing this! Nov 30, 2022 at 15:39
1

If you want to empty the file with a simple mapping, then you can use:

nnoremap <Leader>g ggdG

This will map your leader key + g to execute the following:

  • gg - Bounce to the first line in the file
  • dG - This will delete the current line until the end of the file

Let me know if this answered your question!

2
  • To use D. Ben Knoble's answer, you can map <Leader>g :%delete<CR>. Nov 30, 2022 at 15:45
  • @D.BenKnoble I fixed up my answer. Thank you for your help! Dec 1, 2022 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.