Copy partial rows in VI

There are many different ways you can pull out complete single / multiple lines. Is there a way in which we can copy individual lines to vi, for example, only 10 characters of a line.

+6
source share
8 answers

I would suggest that the most common partial Yankees are:

yaw : hold the word that is currently in the know 2yaw : hold the word cursor in the current and next (total 2 words)
ya( : keep matching parentheses containing the cursor
yf. : from cursor to next .
y$ : pull the cursor to the end of the line

You can use any navigation keys.

+10
source

You can do y Move, so for 10 characters: y10l yanks 10 characters from (and including) the current cursor position

+4
source

Cut and Paste:

Place the cursor where you want to start cutting.

  • Press v to select characters (or uppercase V to select whole lines).
  • Move the cursor to the end of what you want to cut.
  • Press d to cut (or y to copy).
  • Move to where you want to paste.
  • Press P to paste before the cursor, or p to paste after.
  • Copy and paste is performed with the same steps, with the exception of step 4, where you press y instead of d :

d = delete = cut

y = yank = copy

Resource: vim.wikia.com: copy, cut and paste

+3
source

I prefer to just press the v key and then use the cursor keys to move your selection. Then press y when you are satisfied to take out the selection.

+2
source

you can also do

 yt<char> - tank 'till char - i use that a lot or y/<pattern>/ - yank until pattern 
+2
source

Of course, with the cursor at the beginning of the line, enter:

 y10l 

It takes 10 characters to the right. If you need to do this several times for some reason, just add this temporary cap display:

 :noremap ,m ^y10l 

Which will delete the first 10 characters of any line each time it is pressed ,m

+1
source

If you have multiple lines to copy, try the visual block mode,

 " beginning of line Cv " up-down move 10j or 5k 10l " copy & paste y p 

more details see wiki

+1
source

This is one place that can actually hit the keyboard, especially if the current mouse cursor is far from the copy target, or if you want to select multiple lines with a partial start or end line.

Use :set mouse=a to enable mouse support. Then select any irregular text blocks with the mouse, and then press y

0
source

Source: https://habr.com/ru/post/927176/


All Articles