home
目录中创建一个名为.vimrc
的文件,即~/.vimrc
,并在文件中添加
filetype indent plugin on
我得到了预期的缩进行为。这对你有用吗?
我注释掉了以下这行代码,问题得到了解决。之后也没有对注释进行任何奇怪的更正。
set smartindent
为了缩进,以下是设置:
filetype plugin on
filetype indent on
set autoindent
python-mode
没有问题。无论使用还是不使用python-mode
,set smartindent
都会出现问题。set smartindent
与我的折叠方法不兼容。这样的设置放在C:/vim/vimfiles/ftplugin/python.vim
中。setlocal formatoptions=crnqj
以下是使用的字符对应关系,但似乎没有任何问题。
c
: Auto-wrap comments using textwidth, inserting the current comment leader automatically.
r
: Automatically insert the current comment leader after hitting <Enter>
in Insert mode.
n
: When formatting text, recognize numbered lists. This actually uses
the 'formatlistpat' option, thus any kind of list can be used. The
indent of the text after the number is used for the next line. The
default is to find a number, optionally followed by '.', ':', ')',
']' or '}'. Note that 'autoindent' must be set too. Doesn't work
well together with "2".
Example:
1. the first item
wraps
2. the second item
q
: Allow formatting of comments with "gq".
Note that formatting will not change blank lines or lines containing
only the comment leader. A new paragraph starts after such a line,
or when the comment leader changes.
j
: Where it makes sense, remove a comment leader when joining lines.
简而言之,当编辑Python脚本时所观察到的情况并不仅适用于“Python文件类型”,而是与符号#
(也称为“哈希”)有关。
:verbose set smartindent
确认设置在哪里。如果你想禁用它的filetype=python,可以使用autocmd FileType python setlocal nosmartindent
。 - mattn