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

Re: Re (OOPS): Unable to get syntax highlighting to work for root account

Expand Messages
  • YGirouard
    Ok, I fixed it... all I had to do was to add an alias for vi pointing to /usr/bin/vim in my /root/.bashrc file. Root was using /bin/vi which is the Small
    Message 1 of 9 , Feb 29, 2008
    • 0 Attachment
      Ok, I fixed it... all I had to do was to add an alias for vi pointing to
      /usr/bin/vim in my /root/.bashrc file. Root was using /bin/vi which is the
      Small version, while other accounts were aliasing vi as vim, which is why it
      was working... I was also able to get syntax to work as root by using just
      "vim filename" instead of vi... Silly me... Thanks for pointing me in the
      right direction Tony! :)


      YGirouard wrote:
      >
      > I think I found the issue, but I don't know how to fix it...
      >
      > Looks like the root account is not using the same package of VI the other
      > accounts are using... This is what I get when I type vi --version as my
      > own account: (notice the +syntax instead of -syntax, and the Huge version
      > instead of Small...). How can I fix this for root???
      >
      > VIM - Vi IMproved 7.1 (2007 May 12, compiled Jan 9 2008 08:28:18)
      > Included patches: 1-211
      > Modified by <bugzilla@...>
      > Compiled by <bugzilla@...>
      > Huge version without GUI. Features included (+) or not (-):
      > +arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset
      > +cindent
      > -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info
      > +comments
      > +cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic
      > +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
      > +find_in_path
      > +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand
      > +jumplist
      > +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap
      > +menu
      > +mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm
      > -mouse_jsbterm +mouse_netterm +mouse_xterm +multi_byte +multi_lang
      > -mzscheme
      > -netbeans_intg -osfiletype +path_extra +perl +postscript +printer +profile
      > +python +quickfix +reltime +rightleft -ruby +scrollbind +signs
      > +smartindent
      > -sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static
      > -tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar
      > +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
      > +vreplace
      > +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
      > -xterm_clipboard -xterm_save
      > system vimrc file: "/etc/vimrc"
      > user vimrc file: "$HOME/.vimrc"
      > user exrc file: "$HOME/.exrc"
      > fall-back for $VIM: "/usr/share/vim"
      > Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -g -pipe -Wall
      > -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
      > --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
      > -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
      > -D_FORTIFY_SOURCE=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/local/include
      > -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
      > -I/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE
      > -I/usr/include/python2.5 -pthread
      > Linking: gcc -Wl,-E
      > -Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE
      > -L/usr/local/lib -o vim -lselinux -lncurses -lacl -lgpm -Wl,-E
      > -Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE
      > -L/usr/local/lib
      > /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/DynaLoader/DynaLoader.a
      > -L/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE -lperl -lresolv -lutil
      > -lc -L/usr/lib/python2.5/config -lpython2.5 -lutil -lm -Xlinker
      > -export-dynamic
      >
      >
      > YGirouard wrote:
      >>
      >> Thanks Tony,
      >>
      >> Not sure it applies to my issue though, as it's doing it for every
      >> filetype (conf files, php files, perl, etc). As for the additional
      >> details you asked, it was partially in the "Additional Info" section of
      >> my post but here goes anyway... let me know if that helps:
      >>
      >> I'm using Linux RedHat Fedora Core 7 on a virtual dedicated server. I
      >> only have shell access (no gui).
      >>
      >> The version output of vi echoes this (I put the whole thing anyway in
      >> case...):
      >>
      >> VIM - Vi IMproved 7.1 (2007 May 12, compiled Jan 9 2008 08:28:40)
      >> Included patches: 1-211
      >> Modified by <bugzilla@...>
      >> Compiled by <bugzilla@...>
      >> Small version without GUI. Features included (+) or not (-):
      >> -arabic -autocmd -balloon_eval -browse +builtin_terms -byte_offset
      >> -cindent -clientserver -clipboard -cmdline_compl +cmdline_hist
      >> -cmdline_info -comments
      >> -cryptv -cscope -cursorshape -dialog -diff -digraphs -dnd -ebcdic
      >> -emacs_tags -eval -ex_extra -extra_search -farsi -file_in_path
      >> -find_in_path -folding
      >> -footer +fork() -gettext -hangul_input +iconv -insert_expand +jumplist
      >> -keymap -langmap -libcall -linebreak -lispindent -listcmds -localmap
      >> -menu -mksession
      >> -modify_fname -mouse -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm
      >> -mouse_xterm +multi_byte -multi_lang -mzscheme -netbeans_intg -osfiletype
      >> -path_extra -perl -printer -profile -python -quickfix -reltime -rightleft
      >> -ruby -scrollbind -signs -smartindent -sniff -statusline -sun_workshop
      >> -syntax
      >> -tag_binary -tag_old_static -tag_any_white -tcl +terminfo -termresponse
      >> -textobjects -title -toolbar -user_commands -vertsplit -virtualedit
      >> +visual
      >> -visualextra -viminfo -vreplace +wildignore -wildmenu +windows
      >> +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save
      >> system vimrc file: "/etc/virc"
      >> user vimrc file: "$HOME/.vimrc"
      >> user exrc file: "$HOME/.exrc"
      >> fall-back for $VIM: "/usr/share/vim"
      >> Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -g -pipe -Wall
      >> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
      >> --param=ssp-buffer-size=4 -m32 -
      >> march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE
      >> -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2
      >> Linking: gcc -L/usr/local/lib -o vim -lselinux -lncurses -lacl
      >>
      >>
      >> Tony Mechelynck-2 wrote:
      >>>
      >>>
      >>> Tony Mechelynck wrote:
      >>>> YGirouard wrote:
      >>>>> Problem description: Whenever I switch to the root account using "su -
      >>>>> root",
      >>>>> the syntax highlighting in vi stops working. It works fine when I'm
      >>>>> using my
      >>>>> own account since I added "syntax on" in the file ~/.vimrc, but I
      >>>>> tried
      >>>>> adding the same file to the /root directory and it's not doing
      >>>>> anything for
      >>>>> root. I also tried typing the "syntax on" in vi after launching it as
      >>>>> root,
      >>>>> and nothing happens.
      >>>> [...]
      >>>>
      >>>> Is it for every filetype (including c, html, etc.) or only for some of
      >>>> them
      >>>> (such as help, which is set by a modeline)?
      >>>>
      >>>> Modelines are intentionally disabled for the root account starting at
      >>>> patchlevel 7.0.237 (see http://ftp.vim.org/pub/vim/patches/README and
      >>>> search
      >>>
      >>> Oops! http://ftp.vim.org/pub/vim/patches/7.0/README
      >>>
      >>>> for 7.0.237). This is how I enable them even for root:
      >>>>
      >>>> if exists("+modelines")
      >>>> " the following is required because of SuSE's paranoid /etc/vimrc
      >>>> " and to force 'modeline' on even for root in Vim 7.0.237 and later
      >>>> set modeline modelines=5
      >>>> " the following disables a dangerous modeline in one helpfile
      >>>> if has ('autocmd')
      >>>> au BufReadPost ada.txt setl nomodeline ft=help
      >>>> endif
      >>>> endif
      >>>>
      >>>> Beware that obnoxious modelines have been spotted time and again. The
      >>>> most
      >>>> dangerous options are disabled in them, but maybe some dangerous ones
      >>>> have
      >>>> been mistakenly allowed: if you enable them for the superuser, you're
      >>>> on your
      >>>> own. You may get no problems at all, but if bugs bite you, don't say
      >>>> you
      >>>> weren't warned.
      >>>>
      >>>> Also: Since you mention root and su, I assume you're on a Unix-like OS,
      >>>> but
      >>>> which one? (if Linux, which distro?) And what Vim/gvim version are you
      >>>> using?
      >>>> Please paste the first few files of the output of ":version". Only up
      >>>> to
      >>>> "Features included (+) or not (-)" ought to be enough.
      >>>>
      >>>>
      >>>> Best regards,
      >>>> Tony.
      >>>
      >>>
      >>> >>>
      >>>
      >>>
      >>
      >>
      >
      >

      --
      View this message in context: http://www.nabble.com/Unable-to-get-syntax-highlighting-to-work-for-root-account-tp15767467p15773080.html
      Sent from the Vim - General mailing list archive at Nabble.com.


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Richard Hartmann
      On Sat, Mar 1, 2008 at 4:40 AM, Tony Mechelynck ... To guard against surprise modelines in files, use: This function will check if VIM finds modelines and,
      Message 2 of 9 , Mar 1, 2008
      • 0 Attachment
        On Sat, Mar 1, 2008 at 4:40 AM, Tony Mechelynck
        <antoine.mechelynck@...> wrote:


        > Beware that obnoxious modelines have been spotted time and again. The most
        > dangerous options are disabled in them, but maybe some dangerous ones have
        > been mistakenly allowed: if you enable them for the superuser, you're on your
        > own. You may get no problems at all, but if bugs bite you, don't say you
        > weren't warned.

        To guard against surprise modelines in files, use:

        " This function will check if VIM finds modelines and, if yes, will let you
        " choose if you want to execute them. Edit default to enable or disable,
        " according to your needs. You can use y and n, as well.
        function s:CheckForModelines()
        " 'default' may only be set to e[nable], d[isable] and, for
        convenience, y[es] or n[o]
        let default = 'e'

        if default != 'e' && default != 'd' && default != 'y' && default != 'n'
        echoerr "Error in function CheckForModelines: Please set
        'default' to 'e', 'd', 'y' or 'n'"
        endif
        if !exists('+modelines') || &modelines < 1 || ( !&modeline &&
        !exists('b:modeline') )
        return -1
        endif
        let m=''
        if &modelines>line('$')
        sil exe '%g/\<vim:\|\<vi:\|\<ex:/let m=m."\n".getline(".")'
        else
        sil exe '1,'.&modelines.'g/\<vim:\|\<vi:\|\<ex:/let
        m=m."\n".getline(".")'
        sil exe '$-'.(&modelines-1).',$g/\<vim:\|\<vi:\|\<ex:/let
        m=m."\n".getline(".")'
        endif
        if strlen(m)
        echo m
        let j = '-'
        while j != 'e' && j != 'd' && j != 'y' && j != 'n' && j != ''
        if default == 'e' || default == 'y'
        let j = input('Modelines found! [E]nable
        [d]isable):','','expression')
        elseif default == 'd' || default == 'n'
        let j = input('Modelines found! [e]nable
        [D]isable):','','expression')
        endif
        endwhile
        let &l:modeline = (j=='e' || j=='y' || (j=='' && (default=='e'
        || default=='y')))
        let b:modeline = 1
        endif
        endfunction
        au BufReadPost * call s:CheckForModelines()


        Richard

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... [...] This is a small version and it has -autocmd. As such, it has no support for filetypes, since that support requires several kinds of autocommands:
        Message 3 of 9 , Mar 1, 2008
        • 0 Attachment
          YGirouard wrote:
          >
          > Thanks Tony,
          >
          > Not sure it applies to my issue though, as it's doing it for every filetype
          > (conf files, php files, perl, etc). As for the additional details you asked,
          > it was partially in the "Additional Info" section of my post but here goes
          > anyway... let me know if that helps:
          >
          > I'm using Linux RedHat Fedora Core 7 on a virtual dedicated server. I only
          > have shell access (no gui).
          >
          > The version output of vi echoes this (I put the whole thing anyway in
          > case...):
          >
          > VIM - Vi IMproved 7.1 (2007 May 12, compiled Jan 9 2008 08:28:40)
          > Included patches: 1-211
          > Modified by <bugzilla@...>
          > Compiled by <bugzilla@...>
          > Small version without GUI. Features included (+) or not (-):
          > -arabic -autocmd -balloon_eval -browse +builtin_terms -byte_offset -cindent
          > -clientserver -clipboard -cmdline_compl +cmdline_hist -cmdline_info
          > -comments
          > -cryptv -cscope -cursorshape -dialog -diff -digraphs -dnd -ebcdic
          > -emacs_tags -eval -ex_extra -extra_search -farsi -file_in_path -find_in_path
          > -folding
          > -footer +fork() -gettext -hangul_input +iconv -insert_expand +jumplist
          > -keymap -langmap -libcall -linebreak -lispindent -listcmds -localmap -menu
          > -mksession
          > -modify_fname -mouse -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm
          > -mouse_xterm +multi_byte -multi_lang -mzscheme -netbeans_intg -osfiletype
          > -path_extra -perl -printer -profile -python -quickfix -reltime -rightleft
          > -ruby -scrollbind -signs -smartindent -sniff -statusline -sun_workshop
          > -syntax
          > -tag_binary -tag_old_static -tag_any_white -tcl +terminfo -termresponse
          > -textobjects -title -toolbar -user_commands -vertsplit -virtualedit +visual
          > -visualextra -viminfo -vreplace +wildignore -wildmenu +windows +writebackup
          > -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save
          > system vimrc file: "/etc/virc"
          > user vimrc file: "$HOME/.vimrc"
          > user exrc file: "$HOME/.exrc"
          > fall-back for $VIM: "/usr/share/vim"
          > Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -g -pipe -Wall
          > -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
          > --param=ssp-buffer-size=4 -m32 -
          > march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE
          > -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2
          > Linking: gcc -L/usr/local/lib -o vim -lselinux -lncurses -lacl
          [...]

          This is a "small" version and it has -autocmd. As such, it has no support for
          filetypes, since that support requires several kinds of autocommands: for
          instance, $VIMRUNTIME/filetype.vim, which implements filetype detection, sets
          up a huge number of autocommands for the BufRead and BufNewFile events.

          Try invoking vim as vim, not as vi. Does it make a difference?


          Best regards,
          Tony.
          --
          Give me a Plumber's friend the size of the Pittsburgh dome, and a place
          to stand, and I will drain the world.


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... The reason root doesn t use that alias is because /bin is guaranteed to be always mounted when your system is running, even in single-user
          Message 4 of 9 , Mar 1, 2008
          • 0 Attachment
            YGirouard wrote:
            >
            > Ok, I fixed it... all I had to do was to add an alias for vi pointing to
            > /usr/bin/vim in my /root/.bashrc file. Root was using /bin/vi which is the
            > Small version, while other accounts were aliasing vi as vim, which is why it
            > was working... I was also able to get syntax to work as root by using just
            > "vim filename" instead of vi... Silly me... Thanks for pointing me in the
            > right direction Tony! :)

            The reason root doesn't use that alias is because /bin is guaranteed to be
            always mounted when your system is running, even in single-user
            emergency-repairs runlevel, and even if /usr is on a different partition,
            which might be left unmounted in that case.

            What I recommend is not to set up that alias, but instead to teach yourself to
            invoke vim as vim (not vi) whenever you want "big" capabilities such as syntax
            highlighting (and /usr is mounted). That way, if someday you find yourself
            trying to do emergency repairs on a Red Hat system (not necessarily this one),
            you'll know that if "vim" isn't on a mounted volume, you can invoke a minimum
            vim version as "vi" -- while for normal editing purposes on a fully-running
            system, "vim" will give you what you want.


            Best regards,
            Tony.
            --
            You need no longer worry about the future. This time tomorrow you'll
            be dead.


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          Your message has been successfully submitted and would be delivered to recipients shortly.