Vim如何对Python文件进行双倍缩进

9
我了解到你遇到了以下行为。考虑到 settings.py 片段,请注意第33行,按下 'o' 键:
31# Application definition
32 
33 INSTALLED_APPS = [
34     'rest_framework',

I get this

31# Application definition
32 
33 INSTALLED_APPS = [
34         |<-cursor is here, two indents, 8 spaces
35     'rest_framework',

我真正想要的是一个缩进,或者说总共4个空格,和列表其它部分对齐。怎么回事?我使用以下的 .vimrc 配置文件,其中大部分内容来自于 这里
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
2个回答

8

8
根据 @Alik 提供的 python.vim 代码,您可以注意到它默认插入了两个 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

请注意,字典值可以设置为表达式,以便稍后更改“shiftwidth”的值:let g:python_indent.open_paren ='shiftwidth()'(更多解释和选项可在:h ft-python-indent中找到)。 - Cnly

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接