LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-13-2010, 07:05 AM   #1
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
vim - config dependant on current directory?


Hi,

I recently got involved in a project which uses brain-dead GNU indentation style.

So I need to set vim to 2-char tabs when working on that project, but otherwise I want to keep my original configuration.

Is there a way to have options in .vimrc that depend on the current working directory, so I don't have to switch back and forth manually?

Thanks a lot
 
Old 07-13-2010, 07:25 AM   #2
dagbj
LQ Newbie
 
Registered: Jul 2010
Location: Norway
Distribution: Fedora, Ubuntu and RHEL
Posts: 4

Rep: Reputation: 0
I'm not an vim expert. But from what I can see a from looking at the manpage on the vim installed in my system, you can get vim to use different configuration files upon startup:

Quote:
-i {viminfo}
When using the viminfo file is enabled, this option sets
the filename to use, instead of the default "~/.viminfo".
This can also be used to skip the use of the .viminfo file,
by giving the name "NONE".
 
Old 07-13-2010, 11:00 AM   #3
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by dagbj View Post
... you can get vim to use different configuration files upon startup:
Thanks; yes, that would be the workaround -- but it also means I have to use a different command for each.

I'd love it to somehow work automagically.

I.e. I'd need some sort of script in .vimrc which looks at the current working directory and then sets options accordingly.

Only I have no clue if that is possible at all...


EDIT:

ok, it's obviously too hot here, I can't think anymore...

Silly me, all I need is a wrapper which calls vim accordingly...

Thanks anyway

Last edited by rupertwh; 07-13-2010 at 11:03 AM.
 
Old 07-14-2010, 04:29 AM   #4
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Original Poster
Rep: Reputation: 49
solved

The wrapper got me into a nightmare with all the vi vs. vim magic that's already in place.

But it can easily be done in vimrc itself. Yay.
This is my ~/.vimrc now:
Code:
syn on
if 0 == match(getcwd(), "/home/rw/source/braindead")
	set expandtab
	set shiftwidth=2
	set tabstop=2
else	
	set shiftwidth=8
	set tabstop=8
endif
set autoindent
Obviuosly, if I had more than one such project, I'd have to elaborate that a bit, like reading the list of directories from a file.
But for now it's just fine...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
move all files in current directory into a subdirectory in the current directory jakykong Linux - Newbie 8 07-16-2013 11:46 PM
How to untar a file in another directory other then current directory. dr_zayus69 Linux - Software 8 05-16-2007 11:01 AM
adding vim to current install. DotHQ Red Hat 5 05-11-2006 09:08 AM
vim, libacl and libattr in -current hussar Slackware 7 03-28-2006 01:43 PM
VIM Config problems djgerbavore Slackware 5 05-05-2005 09:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration