This is how tabs work. Pressing the Tab doesn't mean "insert n spaces", but rather "go to the next tabstop".
Every line is divided in "cells" of n spaces, for example four:
---->--->--->--->--->--->--->---
Pressing the Tab key will make it go to the start of the next cell (indicated by the >
). In your example there is just one space left to the next tabstop, so only one space is inserted.
The reason it works like this is because the tab key is intended to align data. Consider text like:
Quote | Author |
--------------------+-----------------|
Hello, world | Brian Kernighan |
It's an Aardvark! | Black Adder |
As you can see the two columns are neatly aligned. One way to achieve this is to repeatedly mash the space key until it lines up, but just pressing the tab key once or twice to align it is much easier.
You've chosen to expand tabs with spaces, but that won't change the actual behaviour of how the tab key works; it will still work the same, but instead of inserting a tab character (0x09) it will insert the correct number of spaces. As far as I know, it works like this in all editors and IDEs (at least those that I've used).
If you want Vim to always just insert four spaces you can use:
:inoremap <Tab> <Space><Space><Space><Space>