Question

When using the autoindent configuration from VIM, it will automatically indent your cursor to a meaningful position after creating a new line. But when the first character you enter is a hash character (#) then the indentation will be removed and the # will be inserted as the first character of the line.

Why does this happen? How to configure VIM to not do that?

Example (_ as the empty cursor position):

def python_function():
    _

after clicking the# on the keyboard this happens:

def python_function():
#_

but what should have happened is this:

def python_function():
    #_
Était-ce utile?

La solution

You might have smartindent or cindent instead of (or as well as) autoindent; these indent styles are designed for C-syntax languages. It's a good idea when editing Python to use :filetype plugin indent on as this will load appropriate indent settings for Python.

Autres conseils

:help smartindent

Use the mapping :inoremap # X^H# (^h is entered via CTRL-V CTRL-H)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top