When I enabled expandtab in vim by putting these in .vimrc:

set tw=4
set expandtab

Vim comverted every space typed by me to a newline character.
Like with the above settings whenever I type a new word and hit space
I get a new line.


What I want to type:
while (x < y):

What I get:
  • 1
    is there anything else in your vimrc than those 2 set lines? I've never seen or heard anything like this. What version are you using? What platform? Jan 4, 2019 at 17:46
  • 1
    Its the textwidth line...
    – D. Ben Knoble
    Jan 4, 2019 at 22:32

1 Answer 1


You set the textwith (tw) to 4. So Vim breaks the lines.

I guess you want shiftwidth:

set shiftwidth=4
set tabstop=4
set expandtab
  • That solved it.I wanted tab to be of 4 spaces.In a post I saw tw is for width of tab.Thanks.
    – AVX-42
    Jan 5, 2019 at 9:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.