2008-09-15 47 views
58

我遇到了麻烦,请设置VIM(7.1.xxx)来编辑python文件。 缩进似乎被破坏(最佳4个空格)。 我跟着我通过Google找到的一些教程。仍然没有效果:/ 请帮忙。如何正确设置VIM自动缩进以编辑Python文件 - * .py

+1

你的问题到底是什么?缩进如何打破? – cschol 2008-09-15 17:53:01

+1

你在使用什么平台? Windows/Mac的/ Linux呢? – Jamie 2008-09-15 20:54:29

回答

55

我用这对我的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 

(编辑只显示缩进相关的东西/制表符)

3

确保您正在编辑VIM正确的配置文件。特别是如果您使用的是Windows,那么可以将文件命名为_vimrc而不是其他平台上的.vimrc。

在VIM型

​​

,并查询到_vimrc您的路径/ .vimrc中与

:echo $HOME

:echo $VIM

文件确认您只使用一个文件。如果你想将你的配置分割成更小的块,你可以从你的_vimrc文件中获取其他文件。

:help source

1

更先进的蟒蛇编辑考虑安装simplefold VIM插件。它允许您使用正则表达式进行高级代码折叠。我用它来折叠我的类和方法定义,以便更快地编辑。

10

我用:

$ 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 

不过,但我要去尝试达人的条目

2

一个简单的选择:刚刚取消对配置的以下部分(这是最初注释掉)在/ etc/VIM/vimrc文件:

if has("autocmd") 
     filetype plugin indent on 
    endif