如何正确设置VIM自动注册以编辑Python文件 - *.py

M_1*_*M_1 73 python vim configuration spaces

我很难设置VIM(7.1.xxx)来编辑python文件.缩进似乎被打破(最佳4个空格).我已经按照我通过Google找到的一些教程进行了操作.仍然没有效果:/请帮助.

Dar*_*mas 65

我在我的macbook上使用它:

" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set noexpandtab
au BufRead,BufNewFile *.h set noexpandtab
au BufRead,BufNewFile Makefile* set noexpandtab

" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab           " enter spaces when tab is pressed
set textwidth=120       " break lines when line length increases
set tabstop=4           " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4        " number of spaces to use for auto indent
set autoindent          " copy indent from current line when starting a new line

" make backspaces more powerfull
set backspace=indent,eol,start

set ruler                           " show line and column number
syntax on               " syntax highlighting
set showcmd             " show (partial) command in status line
Run Code Online (Sandbox Code Playgroud)

(编辑为仅显示与缩进/制表符相关的内容)

  • 编辑 C 风格语言时不要使用制表符。s/noexpandtab/expandtab (2认同)

tha*_*nos 13

我用:

$ cat ~/.vimrc
syntax on
set showmatch
set ts=4
set sts=4
set sw=4
set autoindent
set smartindent
set smarttab
set expandtab
set number
Run Code Online (Sandbox Code Playgroud)

但是我要尝试达人的参赛作品

  • 请注意,```smartindent```仅适用于编辑C文件,而不适用于编辑Python文件(至今已被弃用;请参阅http://stackoverflow.com/a/234578/37639). (2认同)

Ted*_*lay 12

一个更简单的选项:只需在/ etc/vim/vimrc文件中取消注释配置的以下部分(最初被注释掉):

    if has("autocmd")
      filetype plugin indent on
    endif
Run Code Online (Sandbox Code Playgroud)