Reputation: 13254
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():
#_
Upvotes: 3
Views: 463
Reputation: 169
For me it was also the case that the indentation was not properly working when I have forgotten to disable paste mode with :set nopaste, when initially turning it on for copy pasting.
Upvotes: 0
Reputation: 157334
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.
Upvotes: 4
Reputation: 212228
:help smartindent
Use the mapping :inoremap # X^H#
(^h is entered via CTRL-V CTRL-H)
Upvotes: 4