Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch between multiple vim configurations with a command or local vimrc files?

Tags:

vim

I work in several groups, each of which has its own tab/indentation/spacing standards in C.

Is there a way to have separate selectable VIM configurations for each so, when I edit a file, either:

  • I do something like set group=1 to select a configuration
  • a local .vimrc that lives in the working directory is used to set the configuration automatically
like image 530
bradreaves Avatar asked Dec 11 '09 17:12

bradreaves


People also ask

How do I change a vimrc file?

Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter. In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file.

How do I open a vimrc file in Vim?

In the terminal, type vi . vimrc . This will create an empty vimrc system file which you want to use. In the file, type set number , and then hit Esc on the keyboard and type in :wq .

What does vimrc file do?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.


1 Answers

I have this in $HOME/.vimrc:

if filereadable(".vim.custom")     so .vim.custom endif 

This allows me to put a .vim.custom file in every directory to load commands and options specific to that directory. If you're working on multiple projects that have deep directory structures you might need something more sophisticated (e.g. walk up the directory tree until a .vim.custom is found), but the same basic idea will work.

UPDATE:

I now do something like this in order to read a .vim file from the same directory as the file I'm editing, regardless of what the current directory is.

let b:thisdir=expand("%:p:h") let b:vim=b:thisdir."/.vim" if (filereadable(b:vim))     execute "source ".b:vim endif 
like image 76
JSBձոգչ Avatar answered Sep 29 '22 20:09

JSBձոգչ