如何在 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 步: 按:Ctrl+v 并选择要注释的行:
Step 2: Press: Ctrl+v and select the lines you want to comment:
第 3 步: Shift-I
#空格(进入 Insert-at-left 模式,输入要插入的字符.选择将消失,但其中的所有行将在第 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屋!