tags:

views:

130

answers:

6

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.

A: 

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

Andrew
Ok. What about quickly navigating so some line (and substring withing the line) and back?
planetp
+3  A: 

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.

Otto Allmendinger
+1 for suggesting the tutorials, they helped me considerably when I started with vim. eg. http://www.vi-improved.org/tutorial.php
ar
+1  A: 
  • 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
WMR
+1  A: 

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;.

Randy Morris
A: 

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.
William Pursell
+3  A: 

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

Haplo