Jon*_*tke 57 python vim comments indentation
每当我想在vim中为缩进行添加注释时,我点击Shift- o(在当前上方打开一个新行,切换到插入模式)并开始键入Python注释(使用#).然后,该哈希神奇地移动到行的开头(没有缩进),我必须单击选项卡几次.
有谁知道如何解决它?
Max*_*Kim 64
我想你set smartindent的.vimrc中有
看到 :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.
Run Code Online (Sandbox Code Playgroud)
我相信你在编写python时不需要smartindenting.所以只需将其从您的设置中删除或将以下内容添加到.vimrc:
au! FileType python setl nosmartindent
Run Code Online (Sandbox Code Playgroud)
试着把它放在.vimrc中:
autocmd BufRead *.py inoremap # X<c-h>#
Run Code Online (Sandbox Code Playgroud)
这将使得散列(磅)符号的插入总是在Python源文件中缩进.