snazzybouche
snazzybouche

Reputation: 2427

Add whitespace to current line in vim

I fairly often find myself in a situation like this:

vim screenshot with cursor at start of line

I'd like to start typing on the line on which my cursor is currently. However, in order to get to the correct indentation level, I'd have to press TAB several times.

Usually I'd press ddO (delete current line and insert a new one above the cursor), which resets my indentation position to the right place:

vim screenshot with cursor at correct position

But that seems like an odd way to go about adding the correct amount of whitespace.

Is there a better way that I'm overlooking?

Upvotes: 1

Views: 196

Answers (2)

Kevin
Kevin

Reputation: 56049

When in normal mode, you can use cc or its synonym S. If you are already in insert mode, Ctrlf is the default key for this, but that can be changed by altering cinkeys (see :h cink for details).

See also this answer on the Vi/Vim stack

Upvotes: 3

D. Ben Knoble
D. Ben Knoble

Reputation: 4673

Kevin mentioned some shortcuts, but another method is <C-i> (indent) and <C-d> (dedent) in insert mode.

Upvotes: 0

Related Questions