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

时间:2020-03-05 18:54:06  来源:igfitidea点击:

我在设置VIM(7.1.xxx)来编辑python文件时遇到麻烦。
缩进似乎已损坏(最佳4个空格)。
我遵循了一些通过Google找到的教程。还是没有效果:/
请帮忙。

解决方案

回答

我在我的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

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

回答

确保我们正在为VIM编辑正确的配置文件。特别是在使用Windows的情况下,在其他平台上,该文件的名称可能是_vimrc而不是.vimrc。

在vim类型

:help vimrc

并使用以下命令检查_vimrc / .vimrc文件的路径

:echo $ HOME

:echo $ VIM

确保只使用一个文件。如果要将配置分成较小的块,则可以从_vimrc文件内部获取其他文件。

:帮助源

回答

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

回答

除其他外,我在python repo中使用vimrc:

http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc

我也加

set softtabstop=4

我在这里更新我的旧配置