 <p>If you are using the "smartindent" indenting option, a fix for your problem is explained in the ":help smartindent" VIM documentation:</p> <blockquote> <pre><code> 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 "&gt;&gt;" command, lines starting with '#' are not shifted right. </code></pre> </blockquote> <p>I use "smartindent" and can confirm that the fix described works for me. It tricks VIM by replacing the keystroke for "#" with typing "X", then hitting backspace, then typing "#" again. You can try this yourself manually and see that it does not trigger the auto-outdenting.</p>