我在设置Vim(7.1.xxx)来编辑Python文件(* .py)时遇到麻烦。缩进似乎已损坏(最佳4个空格)。我遵循了一些通过Google找到的教程。仍然没有效果:/请帮忙。
Answers:
我在Macbook上使用它:
" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set expandtab
au BufRead,BufNewFile *.h set expandtab
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
(已编辑,仅显示与缩进/制表符相关的内容)
我用:
$ 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
但我要尝试达人的作品
smartindent
仅适用于编辑C文件,不适用于Python文件(并且无论如何现在已经不推荐使用;请参见stackoverflow.com/a/234578/37639)。
我在Python回购中使用vimrc:
http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc
我也加
set softtabstop=4
要进行更高级的python编辑,请考虑安装simplefold vim插件。它允许您使用正则表达式进行高级代码折叠。我用它来折叠我的类和方法定义,以便更快地进行编辑。
结合Daren和Thanos提出的解决方案,我们有了一个很好的.vimrc文件。
-----
" 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
set smartindent
set smarttab
set expandtab
set number
" 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