As I mentioned in a recent post, I’ve been using Sublime Text a decent bit. One issue I discovered myself running into was a conflict between tabs and spaces in my code. Running
pylint, for example, would give me output like the following:
Given that Python is based around indentation, this isn’t an uncommon scenario, and one that I would typically rectify easily with the following command in Neovim:
In fact, opening the relevant files in Neovim and running the above command prior to re-running Pylint would resolve the error. Since Sublime will, by default, display whitespace characters when they’re highlighted, I could easily see what was going on. Highlighting a tab would show one contiguous tab character. This mirrored what
pylint reported with there being one character rather than 4. I needed my tabs to be 4 spaces. This initially seemed simple. I just opened my Sublime settings and added the following line:
After saving my settings, I deleted a tab in question and hit the Tab key again. However, I still got a tab character rather than 4 spaces. Odd.
I took to the Internet for some additional searches and eventually came across a Stack Overflow post which said it may be necessary to close each individual file and then re-open each of them. I did just that, closing every open file in the project prior to closing and relaunching Sublime, which I typically do from the CLI in the root of my project’s directory via:
After going through this process, I went back to a line in question, deleted the single tab character, and then validated hitting the Tab key on my keyboard inserted the expected 4 spaces in stead. Re-running
pylint showed that everything was happy. This also resolved a problem I was having where changes implemented by Black would result in issues due to mismatched indentation.