Question

I have already read this:

Vim automatically removes indentation on Python comments

I have tried everything that is mentioned there without success:

  • I have smartindent off
  • I use filetype indent on
  • I tried the trick with :inoremap # X^H#

None of the above helps: Whenever i start a indented line with a # the indentation is removed and the cursor is moved to column 0.

Here's the output of :set: https://gist.github.com/mikehaertl/5387743

And here's the vimrc.local that i use on Ubuntu 12.10: https://gist.github.com/mikehaertl/1612035

So i'm clueless what else i could try. I don't want my cursor to be moved to column 0 whenever i type an indented #. Any suggestions?

UPDATE

So i found out this is caused by cindent. Still this is very obscure to me: Why does vim do that and how can i prevent that from happening if i still want to use cindent?

Was it helpful?

Solution

If you are using cindent, it probably contains the 0# part which comes by default. You just have to remove it, for example by using an auto command to be triggered when the file type changes to the type(s) you want with this indentation disabled.

Is it PHP? If so, adding this line to your .vimrc may help:

autocmd FileType php set cinkeys-=0#

OTHER TIPS

The 'formatoptions' option governs that behavior. What is the output of :set fo?

croql is a good value, see :h fo-table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top