tags:

views:

434

answers:

5

Is it possible to yank an entire block of python code in vim? be it a def, for, if, etc. block..

+4  A: 

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

Vincent
You can use Ctrl-v and y} to see which lines will be yanked. You can press } as you want to cover your block.
noomz
+3  A: 

There's a vim add-on script python_fn.vim which has, as one of its functions, a key binding to visually select a block of Python code using ]v. You could then yank it with y as normal.

Adam Bellaire
+2  A: 

I usually just use visual block mode. Shift-V, move, and 'y'ank the highlighted block. There's only so many shortcuts I can keep in memory at once :)

JimB
This is what I usually do too, I don't think it's the best way, but it's easy enough to do with one brain cell :)
gnibbler
the visual selection is also very useful for indenting/dedenting blocks using > and <
gnibbler
A: 
  1. Enter visual line selection by pressing 'V'
  2. When finished selecting the block pres 'y'
  3. Paste it somewhere with 'p' or 'P'
+1  A: 

You can combine a search with yank, so if your function ends with return retval you can type y/return retval

gnibbler