Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim tab spacing after enter (new line)

Tags:

vim

I've this tab spacing configuration:

set autoindent
set smartindent
set expandtab tabstop=4 shiftwidth=4 smarttab softtabstop=4

and at the end of configuration, I put this:

autocmd FileType javascript,jade,json set shiftwidth=2 tabstop=2 softtabstop=2

The 2 spaces tab works just fine. But, if I type enter (new line), it became 4 spaces. Here is the example:


     var Post = orm.define('Post', {       
       title: sequelize.STRING,      
       content: sequelize.STRING,
         | /* wrong spaces */
     });

But if I use 4 tab spaces, it also use 4 spaces after enter.

I can't figure out what's the problem.

EDIT:

It ONLY happened when I write object-literal in a javascript callback function (like the code example above). It works fine with general code statement and in json object-literal. Here is the example:


    /* the 2 spaces works fine*/
    app.set('port', 3000);
    app.use(express.bodyParser());

    /* also works fine here */
    var config = {
      host: 'localhost',
      port: 5432
    }

like image 648
Kiddo Avatar asked Jul 29 '13 04:07

Kiddo


People also ask

How do I set tab to 4 spaces in Linux?

As for tabs, there are two settings. Within Vim, type a colon and then "set tabstop=4" which will set the tabs to display as four spaces. Hit colon again and type "set expandtab" which will insert spaces for tabs.

How do I Retab in Vim?

vim Whitespace Convert tabs to spaces and spaces to tabs If you enable expandtab again :set expandtab then and run the :retab! command then all the tabs becomes spaces. If you want to do this for selected text then first select the text in visual mode.

Is a tab 4 spaces?

1. Indentation: tabs vs spaces. Java: 4 spaces, tabs must be set at 8 spaces.


1 Answers

Please try using the following:

set smartindent
set tabstop=2
set shiftwidth=2
set expandtab
like image 89
akbarbin Avatar answered Oct 01 '22 07:10

akbarbin