Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3690842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:04:50+00:00 2026-05-19T04:04:50+00:00

I use several different programming languages every day, and I’d like to have different

  • 0

I use several different programming languages every day, and I’d like to have different tab widths (in spaces) for each. For example: I use the “standard” 2 spaces for Ruby, but all our existing Matlab code uses 4 spaces.

I have this from my personal ~/.vimrc:

augroup lang_perl
    au!
    set tabstop=4 " tabstop length N in spaces
    set shiftwidth=4 " make >> and friends (<<, ^T, ^D) shift N, not the default 8
    set expandtab " Use spaces instead of tabs
augroup END

augroup lang_ruby
    au!
    set tabstop=2 " tabstop length N in spaces
    set shiftwidth=2 " make >> and friends (<<, ^T, ^D) shift N, not the default 8
    set expandtab " Use spaces instead of tabs
augroup END

Those work, but the following doesn’t:

augroup lang_matlab
    au!
    set tabstop=4 " tabstop length N in spaces
    set shiftwidth=4 " make >> and friends (<<, ^T, ^D) shift N, not the default 8
    set expandtab " Use spaces instead of tabs
augroup END

I really don’t understand how augroup lang_ruby figures out that I’m editing a Ruby file. (My searches brought up ftdetect, but the solution wasn’t obvious.) It doesn’t seem like vim knows that I’m editing Matlab using augroup lang_matlab. What do I change to make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:04:51+00:00Added an answer on May 19, 2026 at 4:04 am

    If you want to have a large number of settings for {filetype}, you should put them into ~/.vim/ftplugin/{filetype}.vim or into file that matches ~/.vim/ftplugin/{filetype}/**/*.vim (examples: ~/.vim/ftplugin/ruby/foo.vim, ~/.vim/ftplugin/ruby/foo/bar.vim). In this case you don’t need any autocommands at all. If you still want to use autocommands, use the following:

    augroup lang_matlab
        autocmd!
        autocmd FileType matlab      setlocal ts=4 sw=4 et
    augroup END
    

    . Note two things: FileType event (it is there and it is not BufRead,BufNewFile) and setlocal instead of plain set. First is intended to be used for filetype settings, second is how buffer-specific options must be set.

    About why perl and ruby settings work and why matlab settings does not: your example code is just the same as

    augroup lang_perl
        autocmd!
    augroup END
    augroup lang_ruby
        autocmd!
    augroup END
    
    set tabstop=4 " tabstop length N in spaces
    set shiftwidth=4 " make >> and friends (<<, ^T, ^D) shift N, not the default 8
    set expandtab " Use spaces instead of tabs
    
    set tabstop=2 " tabstop length N in spaces
    set shiftwidth=2 " make >> and friends (<<, ^T, ^D) shift N, not the default 8
    set expandtab " Use spaces instead of tabs
    

    So, you effectively set ts=2 sw=2 et. But the $VIMRUNTIME/ftplugin/perl.vim contains the following code:

    setlocal  tabstop=4
    setlocal  shiftwidth=4
    

    so, ts=4 sw=4 for perl is set into ftplugin/perl.vim, not in your vimrc (if you have installed perl-support plugin). You can check it by replacing tabstop=4 with tabstop=8 in vimrc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.