Kurt Keller's Blog

tech notes and more

comments in scripts

When writing scripts, I prefer to have my comments aligned with the code. However, as I use smartindent, vim always moves me to the first column whenever I start a line with hash. Annoying. This annoyance can be disabled, however, with a small entry in your .vimrc configuration file:

:inoremap # X^H#
                        " do not move to left margin when the first character
                        " of a line is # and smartindent is set

Be careful, the ^H part is not two characters but one single control character! In vim you can enter it with CTRL-v followed by H.

Don’t ask me what exactly this setting does. It is remapping what happens when you type a hash mark in insert mode. Instead of what was done before, it will type an X, then a backspace and then the hash character. This way the first character typed on the line is no longer the hash mark. But how exactly this works, I don’t know either.

Share

Leave a Reply