0

I know that this question has most likely been asked many times and I have searched for a solution but I found conflicting answers that didn't solve my issue completely.

I use vim for all of my text editing and I have recently started using Python but I am having issues with indentation. Whenever I tab correctly and everything looks nice in vim, I will get compile errors and I will have to go to an editor like emacs to check where the error actually is.

I've seen some .vimrc files that have configurations to prevent this problem but nothing has worked for me.

Can anyone give me some guidance on this?

KyleCrowley
  • 900
  • 6
  • 14
  • 31

3 Answers3

0

I use a mac, which is built on unix, and here is my .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 

The python relevant stuff boils down to this:

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 

I will get compile errors and I will have to go to an editor like emacs to check where the error actually is.

What's going wrong?

7stud
  • 46,922
  • 14
  • 101
  • 127
  • Thanks for your reply. That seemed to fix the issue. The issue had to do with the tabs. Vim would show proper tabs but when I would go into emacs, it would show improper tagging and I would constantly have to switch between editors which was frustrating. – KyleCrowley Oct 20 '13 at 02:59
0

try to add following snippets to your .vimrc:

autocmd FILETYPE python setlocal expandtab | setlocal shiftwidth=4 |
    \setlocal softtabstop=4 | setlocal textwidth=78 | setlocal tabstop=4
    \set smarttab | set smartindent
yakiang
  • 1,608
  • 1
  • 16
  • 17
0

Another quick way is to set up your Vim environment by Maximum Awesuome or spf13-vim , which not only help you set your indentations, tabs&spaces properly, also install several essential plugins for you.