02/18/2022 14:05 | Category: vim

Tags: vim

swapping tabs with spaces in vim

This is a quick note to reference a helpful StackOverflow post that I read.

Scenario

I ran a flake8 lint and had forgotten that my code had some conflicting space/tab errors. My editor is set for spaces; however, it was during some find/replace (:s/<match>/<replacement>/g) that I had inserted tabs to split a list apart.

SED replace I used

The replace I used was to break a list object from one line into several:

:s/, /,\n\t/g
# before:
list = [
    'some', item', 'here']

# after:
list = [
    'some',
    'item',
    'here']

# final cleanup:
list = [
    'some',
    'item',
    'here'
]

Replacing the tabs

To remedy this, this StackOverflow post recommended using :retab, as it will redo the tabs based on our set tabstop=<your spaces count> setting.