我在vim中完成所有编码并且对它非常满意(所以,请不要"使用不同的编辑器"响应),但是因为smartindent功能想要不缩进以#开头的注释而持续烦恼.例如,我想要
# Do something
$x = $x + 1;
if ($y) {
# Do something else
$y = $y + $z;
}
Run Code Online (Sandbox Code Playgroud)
而不是vim的首选
# Do something
$x = $x + 1;
if ($y) {
# Do something else
$y = $y + $z;
}
Run Code Online (Sandbox Code Playgroud)
我能够阻止评论被发送到线路开头的唯一方法是在点击#之前插入和删除线路上的字符(每次都要记住要做的麻烦)或完全关闭smartindent (当我打开/关闭括号时,失去自动缩进增加/减少).
如何设置vim来维护我的注释缩进而不是将它们发送到行的开头?
Ric*_*ite 45
看起来你在Perl编码.确保在.vimrc中设置以下内容:
filetype plugin indent on
syntax enable
Run Code Online (Sandbox Code Playgroud)
这些将告诉Vim在打开缓冲区时设置文件类型并配置缩进和语法突出显示.无需显式设置smartindent,因为Vim包含的Perl语法文件将自动设置它(以及任何其他Perl特定的自定义).
注意:具有或者set smartindent和/或set autoindent在~/.vimrc可以防止溶液工作.如果您遇到问题,请寻找他们.
Rus*_*lva 17
如果您使用的是"smartindent"缩进选项,则可以在":help smartindent"VIM文档中解释您的问题的修复:
Run Code Online (Sandbox Code Playgroud)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.
我使用"smartindent"并且可以确认所描述的修复对我有用.它通过键入"X"替换键入"#"来欺骗VIM,然后按下退格键,然后再次键入"#".您可以自己手动尝试,看看它不会触发自动缩小.
Ben*_*ein 10
将以下内容放在_vimrc文件中可以解决此问题.
set cindent
set cinkeys=0{,0},!^F,o,O,e " default is: 0{,0},0),:,0#,!^F,o,O,e
Run Code Online (Sandbox Code Playgroud)
更多信息 ......