2

system: ubuntu 14.04.2

I use vim7.4 to write python code, sometimes I want to insert a '#' (comment), then vim takes this '#' to top of line. Maybe I don't explain clearly. example: code:

if 'test' == 'abc':
    print 'something'

I want to insert a '#' in second line.Then this happens:

if 'test' == 'abc':
#   print 'something'

this happens automatically.

but what I want to do just like this:

if 'test' == 'abc':
    # print 'something'
xina1i
  • 748
  • 4
  • 9
  • 21
  • My VIM does this fine in insert mode. – jkd Apr 28 '15 at 02:37
  • http://stackoverflow.com/questions/2561418/how-to-comment-out-a-block-of-python-code-in-vim You must search before post .. – B3mB4m Apr 28 '15 at 02:43
  • @B3mB4m There is no such rule. Also, that post is not a duplicate. – orlp Apr 28 '15 at 02:43
  • 1
    Normally if you have this kind of question, it would be helpful if you experiment with your `.vimrc` by removing lines until you get the exactly line or set of lines that causes this behavior. Then, if you post the minimal `.vimrc`, it will lead to more direct help. – merlin2011 Apr 28 '15 at 06:36

1 Answers1

2

There is an issue with indenting of hash character #: http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash

Q: Why does Vim place # at the first column?

A: You are using 'smartindent', or you have 0# in your 'cinkeys' or 'indentkeys' options.

Under some circumstances, when you type a '#' character while in insert mode, the indent on the current line will be removed. Also, formatting or otherwise attempting to adjust the indent of a line starting with '#' may not work as you expect.

This tip discusses the issues and how problems can be avoided.

Aleksandr K.
  • 528
  • 2
  • 12
  • Thx. This happens, just because my .vimrc file has 'set cindent'. So if I take a comment, it will not happen. – xina1i Apr 29 '15 at 01:45