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

Re: can't source a file inside my _vimrc

Expand Messages
  • Yakov Lerner
    ... What exactly do you mean by without success . Do you get error message ? Which one ? Yakov
    Message 1 of 9 , Mar 1, 2007
    • 0 Attachment
      On 3/1/07, kib2 <kib2@...> wrote:
      > Hi,
      >
      > I had to change my os and I'm now under Vista.
      > I installed Vim 7 and copied my previous _vimrc. All my settings are
      > good but one :
      >
      > the python.vim script
      > (http://www.vim.org/scripts/script.php?script_id=30) is supposed to
      > build a menu, but I've got nothing instead.
      >
      > I've putted this line in my _vimrc, as explained on the python.vim script :
      >
      > au FileType python source C:\Program Files\vim\vim70\scripts\python.vim
      >
      > without success.

      What exactly do you mean by "without success".
      Do you get error message ? Which one ?

      Yakov
    • Yakov Lerner
      ... You re supposed to get additional menus only when you edit the *.py file. Are you editing the *.py file ? Also, try set ft=python manually. Failing that,
      Message 2 of 9 , Mar 1, 2007
      • 0 Attachment
        On 3/1/07, kib2 <kib2@...> wrote:
        > Yakov Lerner a écrit :
        > >
        > > What exactly do you mean by "without success".
        > > Do you get error message ? Which one ?
        > >
        > > Yakov
        > >
        > Hi Yakov,
        >
        > I've got no error message, but no menu too !
        > How can I list all of my available extensions ?

        You're supposed to get additional menus only when
        you edit the *.py file. Are you editing the *.py file ?
        Also, try 'set ft=python' manually. Failing that, try
        to email the plugin author, jvfranklin@...

        Yakov
      • kib2
        ... When I set it manually, it works fine now. So, what should I put inside my _vimrc to have this automaticaly ? Thanks.
        Message 3 of 9 , Mar 1, 2007
        • 0 Attachment
          Yakov Lerner a écrit :
          > On 3/1/07, kib2 <kib2@...> wrote:
          >> Yakov Lerner a écrit :
          >> >
          >> > What exactly do you mean by "without success".
          >> > Do you get error message ? Which one ?
          >> >
          >> > Yakov
          >> >
          >> Hi Yakov,
          >>
          >> I've got no error message, but no menu too !
          >> How can I list all of my available extensions ?
          >
          > You're supposed to get additional menus only when
          > you edit the *.py file. Are you editing the *.py file ?
          > Also, try 'set ft=python' manually.

          When I set it manually, it works fine now.
          So, what should I put inside my _vimrc to have this automaticaly ?
          Thanks.
        • Yakov Lerner
          ... Try :filetype on Yakov
          Message 4 of 9 , Mar 1, 2007
          • 0 Attachment
            On 3/1/07, kib2 <kib2@...> wrote:
            > Yakov Lerner a écrit :
            > > On 3/1/07, kib2 <kib2@...> wrote:
            > >> Yakov Lerner a écrit :
            > >> >
            > >> > What exactly do you mean by "without success".
            > >> > Do you get error message ? Which one ?
            > >> >
            > >> > Yakov
            > >> >
            > >> Hi Yakov,
            > >>
            > >> I've got no error message, but no menu too !
            > >> How can I list all of my available extensions ?
            > >
            > > You're supposed to get additional menus only when
            > > you edit the *.py file. Are you editing the *.py file ?
            > > Also, try 'set ft=python' manually.
            >
            > When I set it manually, it works fine now.
            > So, what should I put inside my _vimrc to have this automaticaly ?

            Try ':filetype on'

            Yakov
          • kib2
            ... filetype on is already inside my mimrc. In fact, I ve made a special function for the different languages I use : au BufEnter *.py exe Fpython()
            Message 5 of 9 , Mar 1, 2007
            • 0 Attachment
              > Try ':filetype on'
              >
              > Yakov
              >
              >
              filetype on is already inside my mimrc.
              In fact, I've made a special function for the different languages I use :


              au BufEnter *.py exe Fpython()

              function Fpython()
              au FileType python source C:\Program Files\vim\vim70\scripts\python.vim
              autocmd BufRead,BufNewFile *.py syntax on
              autocmd BufRead,BufNewFile *.py set ai
              filetype on

              " les tabs sont des espaces pour Python:
              au BufNewFile,BufRead *.py set expandtab
              au BufNewFile,BufRead *.py set tabstop=4
              au BufNewFile,BufRead *.py set shiftwidth=4

              etc...
              endfunction

              Where do I go wrong ?
            • Gary Johnson
              ... If you want vim to automatically detect the file type, filetype on must be executed _before_ any buffer is loaded, that is, before the BufNewFile or
              Message 6 of 9 , Mar 1, 2007
              • 0 Attachment
                On 2007-03-01, kib2 <kib2@...> wrote:
                > > Try ':filetype on'
                > >
                > > Yakov
                > >
                > >
                > filetype on is already inside my mimrc.
                > In fact, I've made a special function for the different languages I use :
                >
                >
                > au BufEnter *.py exe Fpython()
                >
                > function Fpython()
                > au FileType python source C:\Program Files\vim\vim70\scripts\python.vim
                > autocmd BufRead,BufNewFile *.py syntax on
                > autocmd BufRead,BufNewFile *.py set ai
                > filetype on
                >
                > " les tabs sont des espaces pour Python:
                > au BufNewFile,BufRead *.py set expandtab
                > au BufNewFile,BufRead *.py set tabstop=4
                > au BufNewFile,BufRead *.py set shiftwidth=4
                >
                > etc...
                > endfunction
                >
                > Where do I go wrong ?

                If you want vim to automatically detect the file type, "filetype on"
                must be executed _before_ any buffer is loaded, that is, before the
                BufNewFile or BufRead events, and certainly before the BufEnter
                event. Executing "filetype on" is like arming the file detection
                mechanism, but the code above arms the detection _after_ the
                triggering events have occurred.

                So first of all, the "filetype on" line should be in the main body
                of the _vimrc so that it is executed when _vimrc is sourced, not
                later when an autocommand is triggered.

                Secondly, if you want "syntax on", et al. to be executed when you
                enter a buffer containing a Python file, you should either execute
                Fpython() in an autocommand and remove all the autocommands from
                within Fpython(), or you should execute Fpython() unconditionally
                and leave the autocommands within Fpython() as they are. Otherwise,
                the settings within Fpython() won't be executed until the second
                Python file is loaded and vim's behavior will appear to be
                inconsistent.

                Your whole approach is really more complicated and error-prone than
                it needs to be. I would recommend that you take all the settings
                now in Fpython() (except "filetype on"), remove the autocommand
                parts, and put them all in a separate file, C:\Program
                Files\vim\vim70\after\ftplugin\python.vim. Then change all the
                "set" commands to "setlocal", like this:

                source "C:/Program Files/vim/vim70/scripts/python.vim"
                syntax on
                setlocal ai

                " les tabs sont des espaces pour Python:
                setlocal expandtab
                setlocal tabstop=4
                setlocal shiftwidth=4

                Vim's filetype detection will cause this file to be sourced whenever
                you open a Python file. Using "setlocal" will cause those settings
                to apply only to the current buffer, that is, only to buffers
                containing Python files, rather that to every buffer in the current
                vim instance.

                Lastly, if you execute "syntax on" like this, you enable syntax
                highlighting for every buffer, regardless of file type. If you want
                syntax highlighting for only certain file types, I would recommend
                putting

                syntax manual

                in your _vimrc and

                setlocal syntax=ON

                in the C:\Program Files\vim\vim70\after\ftplugin\ file for each
                filetype for which you want highlighting enabled.

                HTH,
                Gary

                --
                Gary Johnson | Agilent Technologies
                garyjohn@... | Mobile Broadband Division
                | Spokane, Washington, USA
              • kib2
                ... Thanks Gary for this long Vim lesson, I ll try to modify my _vimrc now with all your comments in mind. Cheers, Kib.
                Message 7 of 9 , Mar 1, 2007
                • 0 Attachment
                  Gary Johnson a écrit :
                  > On 2007-03-01, kib2 <kib2@...> wrote:
                  >
                  >>> Try ':filetype on'
                  >>>
                  >>> Yakov
                  >>>
                  >>>
                  >>>
                  >> filetype on is already inside my mimrc.
                  >> In fact, I've made a special function for the different languages I use :
                  >>
                  >>
                  >> au BufEnter *.py exe Fpython()
                  >>
                  >> function Fpython()
                  >> au FileType python source C:\Program Files\vim\vim70\scripts\python.vim
                  >> autocmd BufRead,BufNewFile *.py syntax on
                  >> autocmd BufRead,BufNewFile *.py set ai
                  >> filetype on
                  >>
                  >> " les tabs sont des espaces pour Python:
                  >> au BufNewFile,BufRead *.py set expandtab
                  >> au BufNewFile,BufRead *.py set tabstop=4
                  >> au BufNewFile,BufRead *.py set shiftwidth=4
                  >>
                  >> etc...
                  >> endfunction
                  >>
                  >> Where do I go wrong ?
                  >>
                  >
                  > If you want vim to automatically detect the file type, "filetype on"
                  > must be executed _before_ any buffer is loaded, that is, before the
                  > BufNewFile or BufRead events, and certainly before the BufEnter
                  > event. Executing "filetype on" is like arming the file detection
                  > mechanism, but the code above arms the detection _after_ the
                  > triggering events have occurred.
                  >
                  > So first of all, the "filetype on" line should be in the main body
                  > of the _vimrc so that it is executed when _vimrc is sourced, not
                  > later when an autocommand is triggered.
                  >
                  > Secondly, if you want "syntax on", et al. to be executed when you
                  > enter a buffer containing a Python file, you should either execute
                  > Fpython() in an autocommand and remove all the autocommands from
                  > within Fpython(), or you should execute Fpython() unconditionally
                  > and leave the autocommands within Fpython() as they are. Otherwise,
                  > the settings within Fpython() won't be executed until the second
                  > Python file is loaded and vim's behavior will appear to be
                  > inconsistent.
                  >
                  > Your whole approach is really more complicated and error-prone than
                  > it needs to be. I would recommend that you take all the settings
                  > now in Fpython() (except "filetype on"), remove the autocommand
                  > parts, and put them all in a separate file, C:\Program
                  > Files\vim\vim70\after\ftplugin\python.vim. Then change all the
                  > "set" commands to "setlocal", like this:
                  >
                  > source "C:/Program Files/vim/vim70/scripts/python.vim"
                  > syntax on
                  > setlocal ai
                  >
                  > " les tabs sont des espaces pour Python:
                  > setlocal expandtab
                  > setlocal tabstop=4
                  > setlocal shiftwidth=4
                  >
                  > Vim's filetype detection will cause this file to be sourced whenever
                  > you open a Python file. Using "setlocal" will cause those settings
                  > to apply only to the current buffer, that is, only to buffers
                  > containing Python files, rather that to every buffer in the current
                  > vim instance.
                  >
                  > Lastly, if you execute "syntax on" like this, you enable syntax
                  > highlighting for every buffer, regardless of file type. If you want
                  > syntax highlighting for only certain file types, I would recommend
                  > putting
                  >
                  > syntax manual
                  >
                  > in your _vimrc and
                  >
                  > setlocal syntax=ON
                  >
                  > in the C:\Program Files\vim\vim70\after\ftplugin\ file for each
                  > filetype for which you want highlighting enabled.
                  >
                  > HTH,
                  > Gary
                  >
                  >
                  Thanks Gary for this long Vim lesson, I'll try to modify my _vimrc now
                  with all your comments in mind.
                  Cheers,
                  Kib.
                Your message has been successfully submitted and would be delivered to recipients shortly.