我得到以下行为。在此settings.py代码段中,从第33行点击“ o”
31# Application definition
32
33 INSTALLED_APPS = [
34 'rest_framework',
Run Code Online (Sandbox Code Playgroud)
我明白了
31# Application definition
32
33 INSTALLED_APPS = [
34 |<-cursor is here, two indents, 8 spaces
35 'rest_framework',
Run Code Online (Sandbox Code Playgroud)
我真正想要的是一个缩进或总共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
Run Code Online (Sandbox Code Playgroud)
根据@Alik提供的代码python.vim,你可以注意到它shiftwidth 默认插入了2 。
return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2))
Run Code Online (Sandbox Code Playgroud)
但您可以使用g:pyindent_open_paren变量来更改它。
例如:
let g:pyindent_open_paren=shiftwidth()
Run Code Online (Sandbox Code Playgroud)
或者
let g:pyindent_open_paren=4
Run Code Online (Sandbox Code Playgroud)
这是由于Python的默认vim缩进插件引起的。它shiftwidth在下面的第一行插入2 [。
您可以在此处查看导致此行为的代码:https : //github.com/vim/vim/blob/0b9e4d1224522791c0dbbd45742cbd688be823f3/runtime/indent/python.vim#L74
我建议您安装vim-python-pep8-indent完全根据需要在括号内缩进的插件。