When writing C/C++ code, vim defaults to forcing any pound sign ("#") to the zero position column. This is fine for for C/C++, but it is very annoying for shell scripting and perl scripting, since the pound sign is used for comments. For example, if I try to type this:
if [ -e foo.txt ]
then
# This is a comment
# which I want to stay aligned here
do_the_stuff
fi
What I get instead is:
if [ -e foo.txt ]
then
# This is a comment
# which is no longer where I want it to be aligned!
do_the_stuff
fi
...and I have to go and correct this by hand (really slows me down!). Now if I make sure cindent and smartindent are turned off, and turn on autoindent, the annoying "comment-grab" doesn't happen. However, the indentation is not very "smart" and does not respect the syntax as well as when smartindent is turned on. However, smartindent is better, but the auto-grabbing of '#' keeps happening. How can I turn off just the "comment-grab" without messing up the language-dependent indentation smarts? Is there a nifty switch I can just turn on in my .vimrc?
EDIT: I'm running Ubuntu Linux 16.04 x64 vim 7.4.1689
filetypeis set tosh? Also make sure there isn't some strange plugin or setting by starting Vim with minimal settings (see: How do I debug my vimrc file?). – Martin Tournoij Sep 15 '16 at 16:17:h cino-#a look. It seems relevant. – Tumbler41 Sep 15 '16 at 16:29--noplugins, as you suggested, I get the exact same results. There is something withsmartindentwhich is causing this problem. I'm running Ubuntu 16.04 x64 vim 7.4.1689, if that helps. – Doug Barbieri Sep 15 '16 at 16:31