Reputation: 17468
I want to do this:
1 printf("hello world\n");
2 bool func() //I want to cut the comment and insert between line 1 and line 2
3 {
4 //to do
5 }
And, I want to cut the comment after //
and to insert between line 1 and line 2. As I know, by using Ctrl+v
, vim
is transformed into VISUAL
mode, and you can select the text, and by pressing d
, you can cut the text, but How can I insert the text that be cutted and insert into a new line? Is there any command?
And I think after cutting the text, and you can press o
and press esc
and press p
to paste, but it seems to tedious. Are there any better command?
Thank you in advance!
Upvotes: 2
Views: 240
Reputation: 903
Another solution beside the one suggested by FDinoff:
D at the first slash(cuts the comment until end of line)
And run:pu!
(put the content above the current line.)
Upvotes: 1
Reputation: 31419
If you want to save keystrokes you can insert the "
register in insert mode by using <c-r>"
.
Also you can delete from the cursor to the end of the line with D
, which places the deleted section in the "
register.
So if your cursor was on the first character of the comment you can use
DO<c-r>"
to transfrom
printf("hello world\n");
bool func() //I want to cut the comment and insert between line 1 and line 2
{
//to do
}
Into
printf("hello world\n");
//I want to cut the comment and insert between line 1 and line 2
bool func()
{
//to do
}
All you have to do is clean up the trailing white space after func()
.
Take a look at :help i_CTRL-R
to learn more about <c-r>
in insert mode.
Upvotes: 5