开发者

How to block (column?) paste in vim

how can i paste something on multiple lines?

i'm trying to achieve the same as: In an existing text, I can <C-v>jjjjj<S-I>HelloWorld<CR> to have HelloWorld inserted in 5-rows

but instead of typing HelloWorld I'd like to get the text from a register. 开发者_StackOverflowi want to first yank HelloWorld then insert it in 5 lines.


When you are in insert mode, you can press Ctrl-R followed by the letter for the buffer you wish to paste. Then just press Escape as usual and it will be block inserted as normal.


Let's say you have the following in a vim buffer:

1|  Do the dishes
2|  Get milk
3|  Take out the trash

and you want to insert [ ] at the start of each line, so that it becomes:

1|  [ ] Do the dishes
2|  [ ] Get milk
3|  [ ] Take out the trash

  1. go to column one of row one
  2. press CTRL + V (block select)
  3. press j two times (to row three). now the first column of lines one, two, and three are selected
  4. press I (shift + i - capital "i") - this is "block insert mode"
  5. type [ ]
  6. press esc (escape)
  7. text will be inserted on each row


You could use a macro to do this, like qq0Pjq4@q

qq starts a macro with the name q

0 goes to the beginning of the line and P pastes the yanked content before the cursor

j goes down one line and q ends the macro

4@q repeats the q macro 4 times

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜