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.
views:
130answers:
6How do I select a chunk of text and paste it to the current cursor position w/o using mouse in vim?
Use "p" to paste after the current line, and "P" to paste above the current line.
Very simple method:
- Select the lines with
Shift-V
- "Yank" (=copy) the text with
y
- 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.
- 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 withshift/ctrl-v
and theny
- move back to your previously marked position with
`a
(backtick) - paste your buffer with
p
orP
My normal method would be:
- Use visual mode to select the text with v, V, or Ctrl+v
- Yank using y
- Go to the line you want to be on using
123G
or:123
- Navigate where I want to be within that line with t or f
- 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;.
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.
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