Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
985 views
in Technique[技术] by (71.8m points)

vim - Set tab as 2 spaces in vimrc, but still set to 4 spaces when editing python files

I've set tab to equal 2 spaces in my vimrc. This works when I edit java files, but for some reason when I edit python files, tab is set to 4 spaces instead.

My vimrc:

filetype plugin indent on
syntax on

set backspace=indent,eol,start

set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set showtabline=2

set number
set showcmd
set cursorline
set wildmenu
set lazyredraw
set showmatch


call plug#begin('~/.vim/plugged')

Plug 'scrooloose/nerdtree'
Plug 'drewtempelmeyer/palenight.vim'
Plug 'NLKNguyen/papercolor-theme'
Plug 'rakr/vim-one'
Plug 'morhetz/gruvbox'
Plug 'tpope/vim-commentary'
Plug 'ajh17/VimCompletesMe'
Plug 'sheerun/vim-polyglot'

call plug#end()

highlight ColorColumn ctermbg=gray
set colorcolumn=81
autocmd BufNewFile,BufRead * setlocal formatoptions=croqtn textwidth=80

set t_Co=256
set term=xterm-256color
let g:gruvbox_contrast_dark='dark'
colorscheme gruvbox
set background=dark

map <C-x> :NERDTreeToggle<CR>
noremap <TAB> <C-W>w  

" autoclose matching quotes, braces and parentheses
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O
inoremap jj  <Esc>
inoremap <Esc> <Nop>
inoremap <expr> <CR> pumvisible() ? "<C-y>" : "<C-g>u<CR>"
inoremap <C-y> <C-o>h
inoremap <C-u> <C-o>l
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is set automatically in filetype's python plugin.

ftplugin/python.vim

if !exists("g:python_recommended_style") || g:python_recommended_style != 0
    " As suggested by PEP8.
    setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
endif

So you can disable it with:

let g:python_recommended_style = 0
filetype plugin indent on
syntax on
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...