Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to yank an entire block in Vim?

Tags:

python

vim

Is it possible to yank an entire block of Python code in Vim?

Be it a def, for, if, etc. block...

like image 248
john2x Avatar asked Oct 07 '09 13:10

john2x


People also ask

How do I yank a block in vim?

You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before).

How do I yank a whole file in Vim?

The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste. Explanation: % to refer the next command to work on all the lines. y to yank those lines.

How to yank paragraph in Vim?

Copying (Yanking)yy - Yank (copy) the current line, including the newline character. 3yy - Yank (copy) three lines, starting from the line where the cursor is positioned. y$ - Yank (copy) everything from the cursor to the end of the line. y^ - Yank (copy) everything from the cursor to the start of the line.


2 Answers

You can yank a paragraph with y}. This will not yank all the methods if you have a blank line though.

like image 154
Vincent Avatar answered Oct 22 '22 02:10

Vincent


If you want to yank everything except the { use yi{ (or yi}). If you to include the curly braces use ya{ (or ya}).

The i and a modifiers mean in and all.

To yank a word no matter where in the word you are: yiw

To yank the contents of parentheses: yi); if you want to include them, use ya(

You can do the same for " or ' with yi", ya" or yi' and ya'.

Of course, you're not limited to yanking. You can delete a word with diw or change it with ciw, etc... etc...

like image 30
Nathan Fellman Avatar answered Oct 22 '22 03:10

Nathan Fellman