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 7734277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:12:35+00:00 2026-06-01T07:12:35+00:00

I use (Mac)Vim in my projects set to use 2 spaces for tabs and

  • 0

I use (Mac)Vim in my projects set to use 2 spaces for tabs and even have a script which converts all tabs to 2 spaces on save.

When I work with other developers though, sometimes they use tabs instead of spaces and I am looking for a quick way to switch two different vim configurations, would love to switch them on the command line, like this

macvim --oh-no-not-tabs-again .

What’s the best practice on this?

  • 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-06-01T07:12:36+00:00Added an answer on June 1, 2026 at 7:12 am

    You can have autocommands fired on a per-directory basis, so you can configure anything you want automatically without hotkeys. Here’s what I came up with:

    " set up global defaults, these are mine
    set tabstop=4
    set softtabstop=4
    set shiftwidth=4
    set smarttab
    set expandtab
    set autoindent
    set smartindent
    
    " override tab settings on a per-directory basis
    function! SetStandardTabs()
      set noexpandtab
      set tabstop=8
      set softtabstop=4
    endfunction
    
    augroup PerDirectoryTabs
      autocmd!
      autocmd BufRead,BufEnter,BufNewFile /path/to/csharp/files/* call SetStandardTabs()
    augroup END
    

    This configures vim to automatically figure out when you’re in a subtree of /path/to/csharp/files and sets the buffer-local variables the way you want. Put it in your .vimrc and you’re good to go.

    Edit Here’s some code to put in your .vimrc that searches up the tree for the nearest “local” .vimrc and sources (loads) it. Use with caution! Don’t set globals or do anything “interesting”, you’ll get hard-to-diagnose behaviors. I have not exhaustively tested it. It might eat your children. You have been warned!

    " per-subtree .vimrc
    function! FindAndSourceLocalVimrc()
      if exists('g:inFindLocalVimrc')
        return
      endif
      let g:inFindLocalVimrc=1
    
      let v = findfile('.vimrc', '.;')
      if exists('v')
        let v = fnamemodify(v, ':p')
        if v != $MYVIMRC
          exe "source " . v
        endif
      endif
    
      unlet g:inFindLocalVimrc
    endfunction
    
    call FindAndSourceLocalVimrc()
    

    I’m sure 10 years from now I’ll find some already-existing built-in way to do it in one line.

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

Sidebar

Related Questions

I need to use C# on Mac, and I have Mono. What command line
I use Mac as my primary OS, but I often work on ASP.NET MVC
I'm trying to use the desert colorscheme for vim in bash on my Mac
I have set up a .rvmrc file for my project, which simply looks like
First of all, I love vim. I have been using vim for a few
I have made the move from TextMate to VIM. I can not use macvim,
Basically, I have NERDTree installed in Vim (Mac OS X 10.7 Lion). I want
I would like to use network MAC addresses as a unique machine id for
I use terminal from Mac OS X Leopard to connect to remote Linux machines
When I use qtcreator on mac, it creates universal binaries. Does anyone know how

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.