0

I used < in visual model to do a shift+tab reverse for a code inside loop after I removed the try/except phrase. Now, I get an error:

$ python clean_captions.py 
  File "clean_captions.py", line 157
    split = get_split()
                      ^
TabError: inconsistent use of tabs and spaces in indentation

Is there an automated way in vim or command line in Linux to fix this? I am using CentOS 7.

1
  • 2
    Welcome to Vi and Vim! It might be helpful if you edit to include what's wrong and how you want to change it: are there tabs that need to be spaces? vice-versa? how many? Even sample input/output will help.
    – D. Ben Knoble
    Sep 9 '20 at 20:19
3

The problem occurred because there is an inconsistency between the spaces and tabs used for indentation in your code. You have probably opened a tab indented code, and started editing it, while vim was set to indent using spaces. To solve this issue, first, set your tabbing space setting in your ~/.vim/vimrc by

set softtabstop=4
set tabstop=4
set shiftwidth=4
set expandtab

Then, use :retab to fix the indentation issue in your code.

2
  • 4
    Welcome to Vi and Vim! It might help the OP and others if you explain how this helps fix the problem.
    – D. Ben Knoble
    Sep 9 '20 at 20:18
  • just :retab works for me
    – Lucas
    Jul 11 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.