简体   繁体   中英

Options for .vimrc from command-line arguments?

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.

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

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.

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.)

From the excellent answers above, I got this working:

~/.vimrc :

if exists('FLAG')       " 'FLAG' passed from ~/.bashrc 'vimm' alias
    set textwidth=150   " (launches vim in expanded terminal window)
    set lines=58
else
    set textwidth=79
    set lines=40
endif

~/.bashrc :

# Needed to combine following two lines for ~/.vimrc use:
#   alias vimm='konsole --geometry 1900x1040+0+0 -e "bash -c \"vim\""; exit'
#   vim --cmd 'let FLAG=1'
str="'let FLAG=1'"
alias vimm='konsole --geometry 1900x1040+0+0 -e "bash -c \"vim --cmd $str\""; exit'

Now, 'vim' (normal use) launches Vim in a normal-sized terminal, whereas 'vimm' launches Vim in a larger terminal (alternate settings).

'Konsole' is the terminal that I use in Arch Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM