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

Missing syntax highlighting

Expand Messages
  • Don Stefani
    I m kind of new to using vim full time so I hope this is not a stupid question. I couldn t find anything in help that would answer this. A while back when I
    Message 1 of 9 , Aug 23, 2004
      I'm kind of new to using vim full time so I hope this is not a stupid
      question.
      I couldn't find anything in help that would answer this.

      A while back when I upgraded to vim6.3, when I create a new Perl or php
      file, the colored syntax will not
      show up until I close and reopen vim. It used to be that I just had to
      go to another buffer and the back to
      the new file for the syntax highlighting to appear.

      I am posting my _gvimrc below, perhaps I'm missing something?

      gVim 6.3, win XP Pro

      Thank you

      ### _gvimrc file ###########################################

      "set verbose=1
      " Maintainer: Bram Moolenaar <Bram@...>
      " Last change: 2001 Sep 02
      "
      " Make external commands work through a pipe instead of a pseudo-tty
      "set noguipty


      set nocompatible
      set nobackup
      "set fileformat=unix
      "syntax on
      colorscheme don_light3
      set guifont=Courier_New:h10:cANSI
      "set guifont=courier_new:h10:w5:
      "set guifont=Lucida_Sans_Typewriter:h10:cANSI
      set ch=2 " Make command line two lines high
      set guioptions=r,b,T,v,t,g,m,i
      set mousehide " Hide the mouse when typing text
      set virtualedit=all
      set nu
      set autoindent
      set visualbell
      set ruler
      set expandtab " Do not insert tab when <Tab> was pressed - insert a
      number of spaces
      set nowrap
      set shiftwidth=4 " Number of spaces to use for each step of (auto)indent
      set softtabstop=4 " Number of spaces that a <Tab> counts for while
      performing editing operations
      set tabstop=8 " Number of spaces that a <Tab> in the file counts for
      set textwidth=0 " Maximum width of text that is being inserted. A
      longer line will be broken. Zero disables this.
      set bs=2
      "set listchars=tab:\|\ " show tabs with marker

      set showmatch " When a bracket is inserted, briefly jump to the
      matching one
      set nobackup " Do not make a backup before overwriting a file
      set title " Set title to the value of 'titlestring' or to "VIM -
      filename"
      "let g:browsefilter = "All Files (*.*)"

      " Search settings
      set ignorecase " Ignore case in search patterns
      set smartcase " Match "word" case-insensitive and "Word" case-sensitive
      set nohls
      "filetype plugin on
      set aw
      set hi=20 "How many command lines are remembered
      set sh=C:\\WINDOWS\\system32\\cmd.exe "name of the shell program used
      for external commands
      set hidden

      " From VIM.org tips section
      :source C:\Vim\vim63\macros\matchit.vim
      :source C:\Vim\vim63\mswin.vim


      " Make shift-insert work like in Xterm
      "map <S-Insert> <MiddleMouse>
      "map! <S-Insert> <MiddleMouse>

      " Insert templates
      map "x :0r c:\Vim\tmpl\xhtml.html
      "map "c :0r c:\Vim\templates\new_cgi.pl

      " Insert code snippets


      " Only do this for Vim version 5.0 and later.
      if version >= 500

      " I like highlighting strings inside C comments
      let c_comment_strings=1

      " Switch on syntax highlighting if it wasn't on yet.
      if !exists("syntax_on")
      syntax on
      endif

      " Switch on search pattern highlighting.
      set nohlsearch

      " For Win32 version, have "K" lookup the keyword in a help file
      "if has("win32")
      " let winhelpfile='windows.hlp'
      " map K :execute "!start winhlp32 -k <cword> " . winhelpfile <CR>
      "endif

      " Set nice colors
      " background for normal text is light grey
      " Text below the last line is darker grey
      " Cursor is green, Cyan when ":lmap" mappings are active
      " Constants are not underlined but have a slightly lighter background

      endif
    • Terrance Cohen
      You know, I ve seen several questions on this list over time about losing syntax hilighting (including a coulple of my own), and I don t think we ve ever
      Message 2 of 9 , Aug 23, 2004
        You know, I've seen several questions on this list over time about
        losing syntax hilighting (including a coulple of my own), and I don't
        think we've ever really figured it out. I don't know if its one thing
        or many, but it seems that there are operatons that unexpectedly cause
        loss of syntax coloring in a buffer. Since this is, IMHO, one of the
        best features in vim, it would be a shame not to address this issue.

        For example, I liked mruex
        (http://www.vim.org/scripts/script.php?script_id=554), but I stopped
        using it because the following lines in s:MruClose() caused loss of
        syntax coloring on my installation (WinXPPro, GVIM 6.3):

        if s:altbufnr != -1
        exe "b".s:altbufnr
        exe "b".s:curbufnr
        endif

        (If I comment them out, I don't lose syntax coloring, but that causes
        other problems.)

        Could someone who is "in the know" please explain what operations would
        cause loss of syntax coloring in a buffer? In those cases, maybe
        forcing vim to recolor a buffer is the only way to go (what's the best
        way to do that?), but at least we'd know when that needs to be done.

        Any thoughts folks?

        Thanks a lot.

        Terrance Cohen

        Don Stefani wrote:

        > I'm kind of new to using vim full time so I hope this is not a stupid
        > question.
        > I couldn't find anything in help that would answer this.
        >
        > A while back when I upgraded to vim6.3, when I create a new Perl or
        > php file, the colored syntax will not
        > show up until I close and reopen vim. It used to be that I just had to
        > go to another buffer and the back to
        > the new file for the syntax highlighting to appear.
        >
        > I am posting my _gvimrc below, perhaps I'm missing something?
        >
        > gVim 6.3, win XP Pro
        >
        > Thank you
        >
        > ### _gvimrc file ###########################################
        >
        > "set verbose=1
        > " Maintainer: Bram Moolenaar <Bram@...>
        > " Last change: 2001 Sep 02
        > "
        > " Make external commands work through a pipe instead of a pseudo-tty
        > "set noguipty
        >
        >
        > set nocompatible
        > set nobackup
        > "set fileformat=unix
        > "syntax on
        > colorscheme don_light3
        > set guifont=Courier_New:h10:cANSI
        > "set guifont=courier_new:h10:w5:
        > "set guifont=Lucida_Sans_Typewriter:h10:cANSI
        > set ch=2 " Make command line two lines high
        > set guioptions=r,b,T,v,t,g,m,i
        > set mousehide " Hide the mouse when typing text
        > set virtualedit=all
        > set nu
        > set autoindent
        > set visualbell
        > set ruler
        > set expandtab " Do not insert tab when <Tab> was pressed - insert
        > a number of spaces
        > set nowrap
        > set shiftwidth=4 " Number of spaces to use for each step of (auto)indent
        > set softtabstop=4 " Number of spaces that a <Tab> counts for while
        > performing editing operations
        > set tabstop=8 " Number of spaces that a <Tab> in the file counts for
        > set textwidth=0 " Maximum width of text that is being inserted. A
        > longer line will be broken. Zero disables this.
        > set bs=2
        > "set listchars=tab:\|\ " show tabs with marker
        >
        > set showmatch " When a bracket is inserted, briefly jump to the
        > matching one
        > set nobackup " Do not make a backup before overwriting a file
        > set title " Set title to the value of 'titlestring' or to "VIM
        > - filename"
        > "let g:browsefilter = "All Files (*.*)"
        >
        > " Search settings
        > set ignorecase " Ignore case in search patterns
        > set smartcase " Match "word" case-insensitive and "Word"
        > case-sensitive
        > set nohls
        > "filetype plugin on
        > set aw
        > set hi=20 "How many command lines are remembered
        > set sh=C:\\WINDOWS\\system32\\cmd.exe "name of the shell program used
        > for external commands
        > set hidden
        >
        > " From VIM.org tips section
        > :source C:\Vim\vim63\macros\matchit.vim
        > :source C:\Vim\vim63\mswin.vim
        >
        >
        > " Make shift-insert work like in Xterm
        > "map <S-Insert> <MiddleMouse>
        > "map! <S-Insert> <MiddleMouse>
        >
        > " Insert templates
        > map "x :0r c:\Vim\tmpl\xhtml.html
        > "map "c :0r c:\Vim\templates\new_cgi.pl
        >
        > " Insert code snippets
        >
        >
        > " Only do this for Vim version 5.0 and later.
        > if version >= 500
        >
        > " I like highlighting strings inside C comments
        > let c_comment_strings=1
        >
        > " Switch on syntax highlighting if it wasn't on yet.
        > if !exists("syntax_on")
        > syntax on
        > endif
        >
        > " Switch on search pattern highlighting.
        > set nohlsearch
        >
        > " For Win32 version, have "K" lookup the keyword in a help file
        > "if has("win32")
        > " let winhelpfile='windows.hlp'
        > " map K :execute "!start winhlp32 -k <cword> " . winhelpfile <CR>
        > "endif
        >
        > " Set nice colors
        > " background for normal text is light grey
        > " Text below the last line is darker grey
        > " Cursor is green, Cyan when ":lmap" mappings are active
        > " Constants are not underlined but have a slightly lighter background
        >
        > endif
        >
        >
      • Antoine J. Mechelynck
        ... [...] Rather than close and reopen vim, you can reload the current edit file using ... with no arguments. Don t forget to save it first (vim will do it for
        Message 3 of 9 , Aug 23, 2004
          Don Stefani <dev_mail@...> wrote:
          > I'm kind of new to using vim full time so I hope this is not a stupid
          > question.
          > I couldn't find anything in help that would answer this.
          >
          > A while back when I upgraded to vim6.3, when I create a new Perl or
          > php file, the colored syntax will not
          > show up until I close and reopen vim. It used to be that I just had to
          > go to another buffer and the back to
          > the new file for the syntax highlighting to appear.
          [...]

          Rather than close and reopen vim, you can reload the current edit file using

          :e

          with no arguments. Don't forget to save it first (vim will do it for you if
          'autowriteall' is set).

          BTW, which commands do you use to (a) "create a new perl or php file", and
          (b) "go to another buffer and back"? Always be specific.

          HTH,
          Tony.
        • Antoine J. Mechelynck
          ... :enew opens a new buffer with neither filename nor contents, and therefore also no syntax. Try :edit filename.php (or similar) using the
          Message 4 of 9 , Aug 23, 2004
            Don Stefani <dev_mail@...> wrote:
            > Antoine J. Mechelynck wrote:
            >
            > >
            > > BTW, which commands do you use to (a) "create a new perl or php
            > > file", and (b) "go to another buffer and back"? Always be specific.
            > Thanks,
            >
            > I'll use new from the dropdown menu (:enew)
            >
            > I usually have the buffer menu torn off, I'll just click another
            > buffer tab and then back. Than used to bring up the syntax colors.
            >
            > Thanks,
            >
            > dstefani

            ":enew" opens a new buffer with neither filename nor contents, and therefore
            also no syntax. Try ":edit filename.php" (or similar) using the
            not-yet-existing name that you want to give your file. If the file name
            (including extension) is enough to define the filetype, then it will wake up
            with syntax colouring enabled. If, OTOH, the filetype can only be known
            after reading the file's first line (as for some Unix scripts where the
            first line contains the pathfilename of the interpreter), then you will have
            to input that first line, and then (using :w followed by :e) save and
            re-edit your file.

            HTH,
            Tony.

            P.S. As long as you're not straying off-topic, please use the mailing list
            (for instance "Reply to All"), not only private mail (as with "Reply to
            Sender"). I'm not a professional, just one of many Vim users, and if I don't
            know an answer, or if I err, then if we're talking on the list, someone else
            will jump in.
          • Scott Bronson
            ... Does ... have any effect? It might be easier than closing and reopening. I need to do this so much, I have it mapped to F11: map :syn sync
            Message 5 of 9 , Aug 23, 2004
              On Mon, 2004-08-23 at 09:29, Antoine J. Mechelynck wrote:
              > Rather than close and reopen vim, you can reload the current edit file using
              > :e
              > with no arguments. Don't forget to save it first (vim will do it for you if
              > 'autowriteall' is set).

              Does

              :syn sync fromstart

              have any effect? It might be easier than closing and reopening. I need
              to do this so much, I have it mapped to F11: "map <F11> :syn sync
              fromstart<CR>".

              - Scott
            • Antoine J. Mechelynck
              ... :syn sync fromstart requires that the syntax name be already known. I use it, for example, on some HTML files which may have large regions in italics,
              Message 6 of 9 , Aug 23, 2004
                Scott Bronson <bronson@...> wrote:
                > On Mon, 2004-08-23 at 09:29, Antoine J. Mechelynck wrote:
                > > Rather than close and reopen vim, you can reload the current edit
                > > file using :e
                > > with no arguments. Don't forget to save it first (vim will do it
                > > for you if 'autowriteall' is set).
                >
                > Does
                >
                > > syn sync fromstart
                >
                > have any effect? It might be easier than closing and reopening. I
                > need to do this so much, I have it mapped to F11: "map <F11> :syn sync
                > fromstart<CR>".
                >
                > - Scott

                ":syn sync fromstart" requires that the syntax name be already known. I use
                it, for example, on some HTML files which may have large regions in italics,
                much larger than the Vim window on the file. On such files, the other syn
                sync methods might not look far enough back, and thus fail to find the <I>
                (start italics) tag.

                If you open a buffer with ":enew", it has no filetype and no syntax.
                Inserting data into it will not change that, and you see everything in
                black-and-white. Re-syncing fromstart still doesn't set a syntax name, and
                everything is still in black and white. Using ":w filename" still doesn't
                change the current buffer name and nothing happens either. ":saveas
                filename" might or might not (I'm not sure) trigger the BufRead
                autocommands, which will in turn detect the filetype, trigger the FileType
                autocommands, set the syntax, and trigger the Syntax autocommands. Saving
                and reloading the file is a sure-fire way to trigger the BufRead event,
                which will, if you have filetype on and syntax on, eventually set the proper
                highlight colours.

                If, OTOH, you create a new file with ":e filename" (where "filename" doesn't
                yet exist), that triggers the BufNewFile autocommand event, which detects
                the filetype if it can be known from the filename. For instance, if I do ":e
                foo.htm" where foo.htm doesn't exist yet, I get an empty buffer, and
                anything I type in it is highlighted with HTML colouring.

                Regards,
                Tony.
              • Charles E. Campbell, Jr.
                ... Of course, if you started the file as [No File], doing a :w will present difficulties (E32: No file name). ... assuming that syn on was done in your
                Message 7 of 9 , Aug 23, 2004
                  Antoine J. Mechelynck wrote:

                  >...snip...Saving
                  >and reloading the file is a sure-fire way to trigger the BufRead event,
                  >which will, if you have filetype on and syntax on, eventually set the proper
                  >highlight colours...
                  >
                  >

                  Of course, if you started the file as [No File], doing a ":w" will
                  present difficulties (E32: No file name).
                  Just to be pedantic; an alternative is to:

                  :file [give new filename here]
                  :filetype detect

                  assuming that syn on was done in your <.vimrc>.

                  >If, OTOH, you create a new file with ":e filename" (where "filename" doesn't
                  >yet exist),...
                  >
                  >

                  This is the preferred way to do this. I think the OP was merely
                  confused about :e vs :r myself.

                  Regards,
                  Chip Campbell
                • Don Stefani
                  Charles E. Campbell, Jr. wrote: [snip] ... As OP , let me briefly recap... gvim 6.3 for win user, I don t want to type in the entire path to my linux
                  Message 8 of 9 , Sep 1, 2004
                    Charles E. Campbell, Jr. wrote:
                    [snip]
                    >
                    > :file [give new filename here]
                    > :filetype detect
                    >
                    > assuming that syn on was done in your <.vimrc>.

                    As OP , let me briefly recap...

                    gvim 6.3 for win user, I don't want to type in the entire path to my linux box/file/...
                    ect. So I like to use the save button.
                    When I save a new file, the syntax highlighting was not kicking in.

                    Gleaning from the post above I mapped <F2> to do this, works great and fast.

                    In my _gvimrc file:

                    map <F2> :filetype detect<CR>


                    Piece of pie!

                    Thanks, I hope this can help another.

                    dstefani
                  • KenCheri Randall
                    HI May I also suggest adding the following lines to your .vimrc or _vimrc file: Force file type detection when Save-As is used. autocmd BufFilePost *
                    Message 9 of 9 , Sep 2, 2004
                      HI

                      May I also suggest adding the following lines to your .vimrc or _vimrc
                      file:

                      "
                      " Force file type detection when Save-As is used.
                      "
                      autocmd BufFilePost * filetype detect

                      HTH,

                      Ken Randall
                      kencheri at austin dot rr dot com
                    Your message has been successfully submitted and would be delivered to recipients shortly.