如何在Vim中抽出整个街区?

时间:2021-10-08 19:18:29

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

是否有可能在Vim中抽取整个Python代码块?

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

无论是def,for,if等等块...

11 个解决方案

#1


22  

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

你可以用y}来拉一个段落。如果你有一个空行,这将不会拉动所有方法。

#2


8  

The excellent add-on suite Python-mode includes some key commands to navigate classes, methods, and function blocks.

优秀的附加套件Python模式包括一些用于导航类,方法和功能块的关键命令。

  • To yank a method: yaM (inner method: yiM)

    抽一个方法:yaM(内部方法:yiM)

  • To yank a class: yaC

    抽课:yaC

There are other handy motions, like moving from function-to-function (]]). See the complete list of keys for more.

还有其他方便的动作,比如从功能到功能(]]。有关更多信息,请参阅完整的密钥列表。

#3


6  

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

如果你想除了{use yi {(或yi})之外的其他东西。如果要包括花括号,请使用ya {(或ya})。

The i and a modifiers mean in and all.

i和a修饰符意味着所有。

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

无论你在哪里,都要说一句话:yiw

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

要抽出括号的内容:yi);如果你想包括它们,请使用ya(

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

您可以为“或”与“yi”,“ya”或“yi”和“ya”执行相同的操作。

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

当然,你不仅限于耍弄。你可以用diw删除一个单词或用ciw等改变它......等等......

#4


4  

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.

有一个vim附加脚本python_fn.vim,作为其功能之一,它具有一个键绑定,可以使用v来直观地选择一个Python代码块。然后你可以像往常一样用y猛拉它。

#5


3  

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 :)

我通常只使用视觉块模式。 Shift-V,移动,并突出显示突出显示的块。我只能在内存中保留这么多快捷方式:)

#6


3  

  1. Enter visual line selection by pressing 'V'
  2. 按'V'输入视线选择

  3. When finished selecting the block pres 'y'
  4. 完成选择块'y'后

  5. Paste it somewhere with 'p' or 'P'
  6. 用'p'或'P'粘贴它

#7


3  

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

您可以将搜索与yank结合使用,因此如果您的函数以return retval结尾,则可以键入y / return retval

#8


1  

I made a plugin named spacebox which does a Visual selection of all lines with the same or more indentation as the current line.

我创建了一个名为spacebox的插件,它对所有行进行Visual选择,并使用与当前行相同或更多的缩进。

With Python whitespace being the way it is, you could place your cursor on the line below def or if, and issue the command :SpaceBox to select your "block".

使用Python空格就可以了,你可以将光标放在def或if下面的行上,并发出命令:SpaceBox来选择你的“块”。

#9


0  

Just fold the class using za and then use visual mode ( V ) to select the collapsed class. This way you don't have to scroll too much. Then just yank with y. When you are done yanking unfold the class with za again.

只需使用za折叠类,然后使用可视模式(V)选择折叠的类。这样您就不必滚动太多了。然后用y猛拉。当你完成yanking再次展开za类。

#10


0  

  1. In .py file, press Esc
  2. 在.py文件中,按Esc

  3. Press shift V to enter visual line mode
  4. 按shift键进入可视线模式

  5. Highlight with up and down arrow keys
  6. 使用向上和向下箭头键突出显示

  7. Press d to delete the selected rows
  8. 按d删除所选行

  9. Go to the row you would like to place the lines and press p to paste lines after a row or press shift P to paste before a row
  10. 转到要放置线条的行,然后按p键在一行后粘贴线条或按住Shift键在一行前粘贴

Hope that helps.

希望有所帮助。

#11


0  

vim-indent-object works pretty well. Worth a shot.

vim-indent-object工作得很好。值得一试。

#1


22  

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

你可以用y}来拉一个段落。如果你有一个空行,这将不会拉动所有方法。

#2


8  

The excellent add-on suite Python-mode includes some key commands to navigate classes, methods, and function blocks.

优秀的附加套件Python模式包括一些用于导航类,方法和功能块的关键命令。

  • To yank a method: yaM (inner method: yiM)

    抽一个方法:yaM(内部方法:yiM)

  • To yank a class: yaC

    抽课:yaC

There are other handy motions, like moving from function-to-function (]]). See the complete list of keys for more.

还有其他方便的动作,比如从功能到功能(]]。有关更多信息,请参阅完整的密钥列表。

#3


6  

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

如果你想除了{use yi {(或yi})之外的其他东西。如果要包括花括号,请使用ya {(或ya})。

The i and a modifiers mean in and all.

i和a修饰符意味着所有。

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

无论你在哪里,都要说一句话:yiw

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

要抽出括号的内容:yi);如果你想包括它们,请使用ya(

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

您可以为“或”与“yi”,“ya”或“yi”和“ya”执行相同的操作。

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

当然,你不仅限于耍弄。你可以用diw删除一个单词或用ciw等改变它......等等......

#4


4  

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.

有一个vim附加脚本python_fn.vim,作为其功能之一,它具有一个键绑定,可以使用v来直观地选择一个Python代码块。然后你可以像往常一样用y猛拉它。

#5


3  

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 :)

我通常只使用视觉块模式。 Shift-V,移动,并突出显示突出显示的块。我只能在内存中保留这么多快捷方式:)

#6


3  

  1. Enter visual line selection by pressing 'V'
  2. 按'V'输入视线选择

  3. When finished selecting the block pres 'y'
  4. 完成选择块'y'后

  5. Paste it somewhere with 'p' or 'P'
  6. 用'p'或'P'粘贴它

#7


3  

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

您可以将搜索与yank结合使用,因此如果您的函数以return retval结尾,则可以键入y / return retval

#8


1  

I made a plugin named spacebox which does a Visual selection of all lines with the same or more indentation as the current line.

我创建了一个名为spacebox的插件,它对所有行进行Visual选择,并使用与当前行相同或更多的缩进。

With Python whitespace being the way it is, you could place your cursor on the line below def or if, and issue the command :SpaceBox to select your "block".

使用Python空格就可以了,你可以将光标放在def或if下面的行上,并发出命令:SpaceBox来选择你的“块”。

#9


0  

Just fold the class using za and then use visual mode ( V ) to select the collapsed class. This way you don't have to scroll too much. Then just yank with y. When you are done yanking unfold the class with za again.

只需使用za折叠类,然后使用可视模式(V)选择折叠的类。这样您就不必滚动太多了。然后用y猛拉。当你完成yanking再次展开za类。

#10


0  

  1. In .py file, press Esc
  2. 在.py文件中,按Esc

  3. Press shift V to enter visual line mode
  4. 按shift键进入可视线模式

  5. Highlight with up and down arrow keys
  6. 使用向上和向下箭头键突出显示

  7. Press d to delete the selected rows
  8. 按d删除所选行

  9. Go to the row you would like to place the lines and press p to paste lines after a row or press shift P to paste before a row
  10. 转到要放置线条的行,然后按p键在一行后粘贴线条或按住Shift键在一行前粘贴

Hope that helps.

希望有所帮助。

#11


0  

vim-indent-object works pretty well. Worth a shot.

vim-indent-object工作得很好。值得一试。