8

I am in normal mode, at the end of a line. I want to clear the line (delete all characters of the line), and drop into insert mode so that I can start writing something else on that line. Is there a Vim shortcut for this?

Ideally, I would like to preserve the leading whitespaces on the line, but even if I can't that should be fine.

Rushi Agrawal
  • 3,208
  • 2
  • 21
  • 26

3 Answers3

19

You can use S or cc to do that (synonyms). They will keep your indentation if the autoindent option is on. Both can accept an optional count if you want to remove multiple lines.

sidyll
  • 57,726
  • 14
  • 108
  • 151
5

You're looking for :help cc. Without a [count], cc deletes the entire current line and goes into insert mode. Works from anywhere in the line, not just at the end. Depending on your intent settings, that will be preserved, too.

Possible alternatives: A<C-u>, or ddO.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
0

I do not know the shortcut. But just to add, we can do this normally by using first "dd" to delete the line and pressing "o" to enter into insert mode for the deleted line.

Kaushal
  • 27
  • 2
  • 2
    After `dd`, the cursor is on the following line, and `o` inserts after that, so it'd be off by one. You need (capital) `O` to insert above. – Ingo Karkat Sep 27 '18 at 06:55