Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Options for .vimrc from command-line arguments?

Tags:

vim

I have a custom .vimrc file which I use across many different machines.

Some machines are less powerful than others, and it would be nice to be able to load a "stripped-down" version of the .vimrc file. However, I'd like to maintain a single .vimrc to avoid fragmentation.

Ideally, I'd like to pass arguments to my .vimrc from the command line. If the "minimal" option is selected, the .vimrc would skip over loading the most resource-intensive plugins.

Does anyone know the best/cleanest way to do this?

Thanks!

Edit: The slower machine I'm talking about is a Raspberry Pi over SSH. Vim itself isn't slow, although I have several plugins including NERDTree and Syntastic that take lots of time to load on the Pi's limited CPU. By taking out most plugins for my "minimal" configuration, I cut down the loading time from 3.5 seconds to 0.5 seconds.

like image 604
Bill Avatar asked Jan 14 '14 19:01

Bill


3 Answers

You can use the --cmd switch to execute a command before any VIMRC is loaded.

So on your less powerful machines you could alias vim to something like vim --cmd 'let weak=1' and then in your $VIMRC you can say:

if exists('weak')
  echo "poor machine"
endif
like image 78
verdammelt Avatar answered Oct 03 '22 18:10

verdammelt


take a look at source:

source /foo/bar/another_vimrc

Your 'heavy' vimrc can just source the basic vimrc and add what you want. This is also really handy for project/machine specific abbreviations, ctags, etc.

like image 44
Ken Avatar answered Oct 03 '22 19:10

Ken


This will not keep a single vimrc file, but for the sake of others who have the same question (as stated at the top of the page):

$ vim -u ~/.vim-min.vim

Note that this will suppress loading both the system vimrc file (if any) and your personal vimrc file.

:help -u
:help startup

(See Step 3 of the second reference.)

like image 25
benjifisher Avatar answered Oct 03 '22 19:10

benjifisher