How can I convert tab to space in vim?

Viewed 41

What I want is converting tab key to space in vim editor. For example if I enter [tab] key, then it converts to 4 spaces.

I added the following setting in .vimrc

set tabstop=4
set expandtab
set shiftwidth=4

When I enter the first tab, it moves the cursor to position 5 not position 4. But from the second tab, cursor moves to the position 9, 13, 17 and so on.

Only the case of the first tab seems not correct. What did I do wrong?

1 Answers

Columns are counted starting from 1.

Two tabs by four spaces each gives 8 spaces in total. But the editor is still in Insert mode, so the cursor gets positioned to column 9 (the one which doesn't exist yet) to allow to input the next char right after the tabs.

And so it is all right.

Related