我得到以下行为。鉴于这个
settings.py
片段,从第 33 行点击“o”
31# Application definition
32
33 INSTALLED_APPS = [
34 'rest_framework',
我明白了
31# Application definition
32
33 INSTALLED_APPS = [
34 |<-cursor is here, two indents, 8 spaces
35 'rest_framework',
我真正想要的是一个缩进,或者总共 4 个空格,与列表的其余部分保持一致。什么给?我正在使用以下 .vimrc,我主要是从here抄袭的。
set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
" Themes
Plugin 'altercation/vim-colors-solarized'
Plugin 'jnurmine/Zenburn'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
au BufNewFile,BufRead *.py set tabstop=4 shiftwidth=4 textwidth=79 expandtab autoindent fileformat=unix
set encoding=utf-8
set nu
let python_highlight_all=1
syntax on
set backspace=indent,eol,start
发生这种情况是因为 Python 默认的 vim 缩进插件。它在
shiftwidth
下面的第一行插入 2 [
。
您可以在此处查看导致此行为的代码:https://github.com/vim/vim/blob/0b9e4d1224522791c0dbbd45742cbd688be823f3/runtime/indent/python.vim#L74
vim-python-pep8-indent
插件,它可以根据您的需要在括号内进行缩进。
python.vim
的代码,你可以发现它默认插入了2个shiftwidth
。
return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2))
但是您可以使用
g:pyindent_open_paren
变量更改此设置。
例如:
let g:pyindent_open_paren=shiftwidth()
或者
let g:pyindent_open_paren=4
:h ft-python-indent
以查看有关 python 缩进的最新文档。一般来说,你应该这样做
filetype plugin indent on
let g:python_indent = {}
let g:python_indent.open_paren = 'shiftwidth()'
let g:python_indent.closed_paren_align_last_line = v:false
然后你应该得到预期的行为。检查 ft-python-indent 帮助页面以获取更多信息。