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.
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 }
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.
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.
1. Indentation: tabs vs spaces. Java: 4 spaces, tabs must be set at 8 spaces.
Please try using the following:
set smartindent
set tabstop=2
set shiftwidth=2
set expandtab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With