如何在Vim中注释掉Python代码块 [英] How to comment out a block of Python code in Vim
问题描述
我想知道Vim中是否有任何键映射可以让我缩进某些代码行(无论这些行是在可视模式下选择的,还是在当前光标位置上方/下方的 n 行) )。
I was wondering if there was any key mapping in Vim to allow me to indent certain lines of code (whether those lines have been selected in visual mode, or n lines above/below current cursor position).
基本上可以转换以下内容的内容
So basically something that converts the following
def my_fun(x, y):
return x + y
至
#def my_fun(x, y):
# return x + y
我可以使用#
或
注释掉相关行。理想情况下,如果给定的行已被注释掉,我也希望使用相同的键盘映射取消注释行。
I am okay with using either #
or """
for commenting out the relevant lines. Ideally, I would also like the same keymapping to uncomment the lines if the given lines have been commented out.
推荐答案
步骤1:转到要评论的第一行的第一列。
Step 1: Go to the the first column of the first line you want to comment.
步骤2 :公关ess: Ctrl + v 并选择要注释的行:
Step 2: Press: Ctrl+v and select the lines you want to comment:
步骤3: Shift - I
# space (输入在左侧插入模式下,键入要插入的字符。选择将消失,但是其中的所有行将在步骤4之后被修改。)
Step 3: Shift-I
#space (Enter Insert-at-left mode, type chars to insert. The selection will disappear, but all lines within it will be modified after Step 4.)
第4步: Esc
这篇关于如何在Vim中注释掉Python代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!