[英]Comments (#) go to start of line in the insert mode in Vim
每当我想在 vim 的缩进行中添加注释时,我都会按Shift - o (在当前行上方打开一个新行,切换到插入模式)并开始输入 Python 注释(使用#
)。 然后该哈希被神奇地移动到行首(无缩进),我必须多次单击选项卡。
有谁知道如何解决它?
我想你已经在你的 .vimrc 中set smartindent
见:h smartindent
When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use this
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.
我相信你在编码 python 时不需要 smartindenting。 因此,只需将其从您的设置中删除或将以下内容添加到您的 .vimrc 中:
au! FileType python setl nosmartindent
试着把它放在你的 .vimrc 中:
autocmd BufRead *.py inoremap # X<c-h>#
这将使井号(井号)的插入在 Python 源文件中始终缩进。
我遇到了这个问题,因为我在使用 cindent 时在 haskell 中遇到了同样的问题。
您可以通过修改cinkeys的内容来配置提示重新缩进的内容:
我在 vimrc 中添加了以下内容以停止#
触发行为
"when you type a hash as the first character stop it triggering reindent
set cinkeys -=0#
您可能想尝试Nerd Commenter ,这是一个插件,允许您自动为大多数语言的行添加注释。 您只需将光标放在您感兴趣的行上并键入, c Space ,该行将被注释掉。 相同的击键将删除注释以显示该行。
所以如果你有:
def func():
print("indented") <- cursor position in command mode
键入, c Space ,您将得到:
def func():
#print("indented")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.