2008-09-15 158 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