Reputation: 13308
I want to replace all the text of the current line under the cursor and c
hange the text so I start typing the new code. But I want to keep the indentation.
Currently I am using ddO
. This will delete the line and open a line before the cursor in insert mode, it's good because vim will take notice of the previous indentation and place the cursor as expected.
But I want to use c
similar to ciw
(change inner word) because it feels natural to think "change the line". Vc
is almost what I want but it will lose the indentation.
Any idea ?
Upvotes: 0
Views: 558
Reputation: 9465
You can try this (to put in your vimrc):
:onoremap ii :<c-u>normal! v^o$h<cr>
:xnoremap ii ^o$h
ii
which will work with any command expecting a motion (cii
, dii
, yii
...).vii
).Brief explanation of the :normal!
command:
v
: visual mode, ^
: go to 1st non-blank char, o
: go to the opposite side of the selection, $h
: go past to the end of line then go 1 char left.Upvotes: 1
Reputation: 1559
Maybe you are looking for cc
?
:h cc
["x]cc Delete [count] lines [into register x] and start insert |linewise|. If 'autoindent' is on, preserve the indent of the first line.
Upvotes: 5