开发者

How do I select a chunk of text and paste it to the current cursor position w/o using mouse in vim?

I want to give up using mouse for selecting and pasting chunks of text within a buffer. Whats the most开发者_高级运维 efficient way to do this with just kb? I mean navigate to arbitrary line, copy the substring, return to the previous position and paste.


Very simple method:

  1. Select the lines with Shift-V
  2. "Yank" (=copy) the text with y
  3. Paste the text with p at the position you want to.

There are of course many other ways to copy and paste, yy copies the current line for example.

Do the some VIM tutorials, it is better than learning everything bit by bit.


If you want to go quickly to a line use the search by typing /SUBSTRING and then Enter after you have found the correct substring. Make sure to use hlsearch and incsearch :set incsearch and :set hlsearch

When you are at the correct line, yank the whole line with yy or the whole word with yaw. Then go back to where you started the search by typing two backticks `` Then you can paste your yanked line/string with p


  • Mark your current position by typing ma (you can use any other letter instead of a, this is just a "named position register".
  • navigate to the line and substring for example by using a / search
  • yank text with y<movement> or mark it with shift/ctrl-v and then y
  • move back to your previously marked position with ```a`` (backtick)
  • paste your buffer with p or P


My normal method would be:

  1. Use visual mode to select the text with v, V, or Ctrl+v
  2. Yank using y
  3. Go to the line you want to be on using 123G or :123
  4. Navigate where I want to be within that line with t or f
  5. Put the text with p or P

If you need to jump back and forth between the spots, I'd cycle through jumps using g, and g;.


Use "p" to paste after the current line, and "P" to paste above the current line.


Not sure what you mean by 'the substring'. If you want to copy line 50 to the current position, use:

:50t.

If you want to move line 50 to the current cursor position, use:

:50m.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜