我知道这个问题很可能已被多次询问过,而且我已经找到了解决方案,但我找到了相互矛盾的答案,并没有完全解决我的问题。
我使用vim进行所有文本编辑,最近我开始使用Python但是我遇到了缩进问题。每当我正确选项并且vim中的所有内容都很好看,我都会遇到编译错误,我将不得不去像emacs这样的编辑器来检查错误的实际位置。
我见过一些.vimrc文件有配置来防止这个问题,但没有任何对我有用。
有人可以给我一些指导吗?
答案 0 :(得分:0)
我使用的是基于unix构建的mac,这是我的.vimrc:
set nocompatible "cannot remember, but necessary for something
syntax on "syntax highlighting
filetype plugin indent on
au FileType htm setlocal expandtab shiftwidth=2 softtabstop=2
au FileType html setlocal expandtab shiftwidth=2 softtabstop=2
au FileType css setlocal expandtab shiftwidth=2 softtabstop=2
au FileType javascript setlocal expandtab shiftwidth=2 softtabstop=2
au FileType xml setlocal expandtab shiftwidth=2 softtabstop=2
au FileType ruby setlocal expandtab shiftwidth=2 softtabstop=2
au BufNewFile,BufRead *.ru set filetype=ruby
au BufNewFile,BufRead *.slim set filetype=ruby
au FileType cgi setlocal expandtab shiftwidth=2 softtabstop=2
au FileType python setlocal expandtab shiftwidth=4 softtabstop=4
au FileType perl setlocal expandtab shiftwidth=4 softtabstop=4
au FileType php setlocal expandtab shiftwidth=4 softtabstop=4
au FileType java setlocal expandtab shiftwidth=4 softtabstop=4
au FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4
au BufNewFile,BufRead *.coffee set filetype=ruby
au BufNewFile,BufRead *.jsp set filetype=html
set textwidth=78
python相关的东西归结为:
set nocompatible "cannot remember, but necessary for something
syntax on "syntax highlighting
filetype plugin indent on
au FileType python setlocal expandtab shiftwidth=4 softtabstop=4
set textwidth=78
我会收到编译错误,我将不得不去编辑 emacs检查错误的实际位置。
出了什么问题?
答案 1 :(得分:0)
尝试将以下代码段添加到.vimrc
:
autocmd FILETYPE python setlocal expandtab | setlocal shiftwidth=4 |
\setlocal softtabstop=4 | setlocal textwidth=78 | setlocal tabstop=4
\set smarttab | set smartindent
答案 2 :(得分:0)
另一种快捷方式是按Maximum Awesuome或spf13-vim设置您的Vim环境 ,它不仅可以帮助您正确设置缩进,标签和空格,还可以为您安装几个必要的插件。