6

In my .vimrc I have set backspace=eol,start, which allows me to backspace over line breaks and the start of what I wrote since I entered Insert mode. This does not allow me to backspace over autoindents though. For that one can add indent to the backspace list.

If one doesn't use indent he may be unable to delete an empty line he just added, because if an autoindent was created it cannot be deleted and therefore the line break cannot be reached and deleted.

On the other hand, when using indent the backspace key deletes only one tab at a time (not sure what it does when indenting with spaces). This can be annoying if you are writing say a deep nested loop.

So my question is: while in Insert mode, is there a way to delete all the autoindents in one line by using the backspace key only once?

2

I like to use Ctrl+U. If there are any characters on the line, it deletes to the beginning of the text. Press again to delete to column 1 (the indentation), and again to remove the line and put the cursor at the end of the line above. This is quicker than Ctrl+D when there are several levels of indent.

This requires indent set in your backspace option.

set backspace=eol,start,indent        " or set backspace=2
  • I knew about <C-u> but I didn't know it could delete the tabs too. I have just tried it: indent is needed for it too work. I think this is quicker, as you wrote. – Gonçalo Ribeiro Feb 12 '15 at 1:55
5

You can do 0<C-d> to delete all indent in the current line in insert mode.

-- edit --

The right way to get help for <C-d> in insert mode is :help i_ctrl-d. The i_ prefix indicates insert mode so you can also use v_ for visual mode or c_ for command-line mode. 0<C-d> is a few lines below <C-d>.

  • Thank you. After reading your answer I researched a bit and found that while in Insert mode <c-t> and <c-d> increase or decrease the indentation level. I tried :h c-d and I couldn't find more info, though... How could I read more about this on the vim documentation? I suggest you add a bit more info to your answer ;) – Gonçalo Ribeiro Feb 11 '15 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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