Loading ...
Sorry, an error occurred while loading the content.

Specifying .vimrc on cmdline

Expand Messages
  • Bahadir Balban
    Hi, I m using vim 6.3.84. If I want to view a C file, and specify the .vimrc file on the command line as below: % vim main.c -u .vimrc The main.c file is not
    Message 1 of 4 , Dec 1, 2005
    • 0 Attachment
      Hi,

      I'm using vim 6.3.84.
      If I want to view a C file, and specify the .vimrc file on the command
      line as below:

      % vim main.c -u .vimrc

      The main.c file is not syntax highlighted. It is the same .vimrc file
      as the one I have for default, which lies in ~/.vimrc. Why do I lose
      the syntax highlighting when I use the option -u? Any suggestions on
      how to switch between .vimrc files on different projects?

      I tried putting .vimrc in my current directory and expect it to
      suffice, but it checks the home directory first, and it overrides the
      one in my current directory. I wish it was the other way around.

      Thanks,
      Bahadir
    • Tim Chase
      ... My first thought is that syntax highlighting is enabled in a system-wide vimrc (likely /etc/vimrc or something of the like), and by specifying your custom
      Message 2 of 4 , Dec 1, 2005
      • 0 Attachment
        > If I want to view a C file, and specify the .vimrc file on the command
        > line as below:
        >
        > % vim main.c -u .vimrc
        >
        > The main.c file is not syntax highlighted. It is the same .vimrc file
        > as the one I have for default, which lies in ~/.vimrc. Why do I lose
        > the syntax highlighting when I use the option -u? Any suggestions on
        > how to switch between .vimrc files on different projects?

        My first thought is that syntax highlighting is enabled in a
        system-wide vimrc (likely /etc/vimrc or something of the like),
        and by specifying your custom vimrc file on the command line,
        it's ignoring the system-wide vimrc file.

        You might try putting a line something like

        source /etc/vimrc

        at the top of your custom vimrc file and see if that enables the
        behaviors you want.

        Additionally, I'm not sure if Vim is picky about the order of
        parameters...whether there's a diff. between

        vim main.c -u .vimrc

        and

        vim -u .vimrc main.c

        Just a few thoughts...

        -tim
      • Tim Chase
        ... As buried in the ... If Vim was started with -u filename , the file filename is used. All following initializations until 5. are skipped. This means
        Message 3 of 4 , Dec 1, 2005
        • 0 Attachment
          > What's confusing though, is that my ~/.vimrc does not override
          > /etc/vim/vimrc and each time I run vim, both are sourced by
          > default, although I don't have a `source' cmd in ~/.vimrc for
          > /etc/vim/vimrc. But supplying .vimrc in the cmdline overrides
          > all others.

          As buried in the

          :help vimrc

          If Vim was started with "-u filename", the file
          "filename" is used.
          All following initializations until 5. are skipped.

          This means that it will skip the system vimrc file as well as the
          loading of plugins. Without the "-u filename" side of things, it
          will proceed by default with the loading of both the system-wide
          vimrc and the loading of plugins.

          The default think-process would be "load the system vimrc file,
          then override it with any settings in the ~/.vimrc for this
          particular user" whereas specifying the "-u" option would be
          something like "these settings are exactly what I want, no more,
          no less".

          -tim
        • A. J. Mechelynck
          ... OK, then you can workaround it:
          Message 4 of 4 , Dec 1, 2005
          • 0 Attachment
            Tim Chase wrote:
            >> What's confusing though, is that my ~/.vimrc does not override
            >> /etc/vim/vimrc and each time I run vim, both are sourced by
            >> default, although I don't have a `source' cmd in ~/.vimrc for
            >> /etc/vim/vimrc. But supplying .vimrc in the cmdline overrides
            >> all others.
            >
            > As buried in the
            >
            > :help vimrc
            >
            > If Vim was started with "-u filename", the file
            > "filename" is used.
            > All following initializations until 5. are skipped.
            >
            > This means that it will skip the system vimrc file as well as the
            > loading of plugins. Without the "-u filename" side of things, it will
            > proceed by default with the loading of both the system-wide vimrc and
            > the loading of plugins.
            >
            > The default think-process would be "load the system vimrc file, then
            > override it with any settings in the ~/.vimrc for this particular user"
            > whereas specifying the "-u" option would be something like "these
            > settings are exactly what I want, no more, no less".
            >
            > -tim
            >
            >
            >
            >
            >
            >
            >
            >

            OK, then you can workaround it:

            <<<<<< ~/__vimrc
            set nocompatible
            if filereadable("/etc/vimrc")
            source /etc/vimrc
            endif
            if filereadable("$HOME/.vimrc")
            source ~/.vimrc
            endif
            <<<<< ~/__vimrc <<<<< end

            $ vim -u ~/__vimrc main.c

            Like this it doesn't make much sense but if you add other ex-commands in
            ~/__vimrc (or /devel/abraca/d/acarba/src/vimrc or whatever) then it will.

            Best regards,
            Tony.
          Your message has been successfully submitted and would be delivered to recipients shortly.