1

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. Commented Sep 9, 2020 at 20:19

1 Answer 1

6

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.

3
  • 4
    Welcome to Vi and Vim! It might help the OP and others if you explain how this helps fix the problem. Commented Sep 9, 2020 at 20:18
  • just :retab works for me
    – Lucas
    Commented Jul 11, 2021 at 18:15
  • :retab did not work for me. I needed to force convert all spaces to tabs. I had to use :%retab!
    – Dave
    Commented Dec 15, 2022 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.