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

colors and vimrc in sudo and su

Expand Messages
  • oversky
    When I use $sudo vim file, vim uses ~/.vimrc, but not the color template in ~/.vim/colors. When I change to super user by su, vim uses some initial vimrc and
    Message 1 of 12 , Nov 1, 2009
    • 0 Attachment
      When I use $sudo vim file, vim uses ~/.vimrc, but not the color
      template in ~/.vim/colors.
      When I change to super user by su, vim uses some initial vimrc and
      color.
      How do I apply the user vimrc, color template and plugin for the above
      two situations?
      I just start using Ubuntu 9.10, and have not used linux before.
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • bill lam
      ... Not sure what you meant by colors not used. Could you give details of the your problem, or did you mean the difference between vim and gvim? -- regards,
      Message 2 of 12 , Nov 1, 2009
      • 0 Attachment
        On Sun, 01 Nov 2009, oversky wrote:
        >
        > When I use $sudo vim file, vim uses ~/.vimrc, but not the color
        > template in ~/.vim/colors.

        Not sure what you meant by colors not used. Could you give details of
        the your problem, or did you mean the difference between vim and gvim?

        --
        regards,
        ====================================================
        GPG key 1024D/4434BAB3 2008-08-24
        gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • sc
        ... what worked for me is this: as root i changed directory to /root -- there i created symbolic links to my ~/.vimrc, ~/.gvimrc, and ~/.vim path, where ~
        Message 3 of 12 , Nov 1, 2009
        • 0 Attachment
          On Sunday 01 November 2009, oversky wrote:

          > When I use $sudo vim file, vim uses ~/.vimrc, but not the
          > color template in ~/.vim/colors.
          > When I change to super user by su, vim uses some initial
          > vimrc and color.
          > How do I apply the user vimrc, color template and plugin
          > for the above two situations?
          > I just start using Ubuntu 9.10, and have not used linux
          > before.

          what worked for me is this: as root i changed directory to
          /root -- there i created symbolic links to my ~/.vimrc,
          ~/.gvimrc, and ~/.vim path, where '~' means the home path of
          my normal user

          sc


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • James Michael Fultz
          ... I think that a better way is to setup environment: # ~/.profile, ~/.bashrc, ~/.zshenv, etc. EDITOR=vim VISUAL=$EDITOR export EDITOR VISUAL and: $ sudoedit
          Message 4 of 12 , Nov 1, 2009
          • 0 Attachment
            * sc <toothpik@...> [2009-11-01 13:27 -0600]:
            > > How do I apply the user vimrc, color template and plugin
            > > for the above two situations?
            > > I just start using Ubuntu 9.10, and have not used linux
            > > before.
            >
            > what worked for me is this: as root i changed directory to
            > /root -- there i created symbolic links to my ~/.vimrc,
            > ~/.gvimrc, and ~/.vim path, where '~' means the home path of
            > my normal user

            I think that a better way is to setup environment:

            # ~/.profile, ~/.bashrc, ~/.zshenv, etc.
            EDITOR=vim
            VISUAL=$EDITOR
            export EDITOR VISUAL

            and:

            $ sudoedit file

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • pansz
            ... for the first case, it should work, ubuntu by default will setup sudo to use the user environment. but ubuntu by default do *not* have the proper version
            Message 5 of 12 , Nov 1, 2009
            • 0 Attachment
              oversky 写道:
              > When I use $sudo vim file, vim uses ~/.vimrc, but not the color
              > template in ~/.vim/colors.
              > When I change to super user by su, vim uses some initial vimrc and
              > color.
              > How do I apply the user vimrc, color template and plugin for the above
              > two situations?
              > I just start using Ubuntu 9.10, and have not used linux before.

              for the first case, it should work, ubuntu by default will setup sudo to
              use the user environment. but ubuntu by default do *not* have the
              proper version of vim installed, you need to :sudo apt-get install vim
              before you can use vim.

              for the second case, you are using root environment, so you can do under
              your user account:
              sudo ln -s ~/.vim /root/.vim
              sudo ln -s ~/.vimrc /root/.vimrc

              then use your su and you can get the same vim env.


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • bill lam
              ... or $ sudo -e file -- regards, ==================================================== GPG key 1024D/4434BAB3 2008-08-24 gpg --keyserver subkeys.pgp.net
              Message 6 of 12 , Nov 1, 2009
              • 0 Attachment
                On Sun, 01 Nov 2009, James Michael Fultz wrote:
                >
                > * sc <toothpik@...> [2009-11-01 13:27 -0600]:
                > > > How do I apply the user vimrc, color template and plugin
                > > > for the above two situations?
                > > > I just start using Ubuntu 9.10, and have not used linux
                > > > before.
                > >
                > > what worked for me is this: as root i changed directory to
                > > /root -- there i created symbolic links to my ~/.vimrc,
                > > ~/.gvimrc, and ~/.vim path, where '~' means the home path of
                > > my normal user
                >
                > I think that a better way is to setup environment:
                >
                > # ~/.profile, ~/.bashrc, ~/.zshenv, etc.
                > EDITOR=vim
                > VISUAL=$EDITOR
                > export EDITOR VISUAL
                >
                > and:
                >
                > $ sudoedit file

                or

                $ sudo -e file

                --
                regards,
                ====================================================
                GPG key 1024D/4434BAB3 2008-08-24
                gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • pansz
                ... sudoedit type 1 more key than sudo vi sudo -e needs the same number of keystrokes, but sudo vi is easier to remember. So why do you think sudo -e or sudo
                Message 7 of 12 , Nov 4, 2009
                • 0 Attachment
                  bill lam 写道:
                  > On Sun, 01 Nov 2009, James Michael Fultz wrote:
                  >> * sc <toothpik@...> [2009-11-01 13:27 -0600]:
                  >>>> How do I apply the user vimrc, color template and plugin
                  >>>> for the above two situations?
                  >>>> I just start using Ubuntu 9.10, and have not used linux
                  >>>> before.
                  >>> what worked for me is this: as root i changed directory to
                  >>> /root -- there i created symbolic links to my ~/.vimrc,
                  >>> ~/.gvimrc, and ~/.vim path, where '~' means the home path of
                  >>> my normal user
                  >> I think that a better way is to setup environment:
                  >>
                  >> # ~/.profile, ~/.bashrc, ~/.zshenv, etc.
                  >> EDITOR=vim
                  >> VISUAL=$EDITOR
                  >> export EDITOR VISUAL
                  >>
                  >> and:
                  >>
                  >> $ sudoedit file
                  >
                  > or
                  >
                  > $ sudo -e file
                  >

                  sudoedit type 1 more key than sudo vi

                  sudo -e needs the same number of keystrokes, but sudo vi is easier to
                  remember.

                  So why do you think sudo -e or sudo edit is better than sudo vi ?


                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • bill lam
                  ... just a habit. actually sudo edit is easier to type than sudo -e because the - is away from home position, that depends on keyboard layout of course. btw
                  Message 8 of 12 , Nov 4, 2009
                  • 0 Attachment
                    On Thu, 05 Nov 2009, pansz wrote:
                    >
                    > bill lam 写道:
                    > > On Sun, 01 Nov 2009, James Michael Fultz wrote:
                    > >> * sc <toothpik@...> [2009-11-01 13:27 -0600]:
                    > >>>> How do I apply the user vimrc, color template and plugin
                    > >>>> for the above two situations?
                    > >>>> I just start using Ubuntu 9.10, and have not used linux
                    > >>>> before.
                    > >>> what worked for me is this: as root i changed directory to
                    > >>> /root -- there i created symbolic links to my ~/.vimrc,
                    > >>> ~/.gvimrc, and ~/.vim path, where '~' means the home path of
                    > >>> my normal user
                    > >> I think that a better way is to setup environment:
                    > >>
                    > >> # ~/.profile, ~/.bashrc, ~/.zshenv, etc.
                    > >> EDITOR=vim
                    > >> VISUAL=$EDITOR
                    > >> export EDITOR VISUAL
                    > >>
                    > >> and:
                    > >>
                    > >> $ sudoedit file
                    > >
                    > > or
                    > >
                    > > $ sudo -e file
                    > >
                    >
                    > sudoedit type 1 more key than sudo vi
                    >
                    > sudo -e needs the same number of keystrokes, but sudo vi is easier to
                    > remember.
                    >
                    > So why do you think sudo -e or sudo edit is better than sudo vi ?

                    just a habit. actually sudo edit is easier to type than sudo -e
                    because the "-" is away from home position, that depends on keyboard
                    layout of course.

                    btw iirc nautilus allows mouse right click to call customised script
                    that bind to 'gsudo gvim file'.

                    --
                    regards,
                    ====================================================
                    GPG key 1024D/4434BAB3 2008-08-24
                    gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • James Michael Fultz
                    ... The latter does not preserve your personal Vim environment. See sudo(8): -e The -e (edit) option indicates that, instead of running a command, the user
                    Message 9 of 12 , Nov 5, 2009
                    • 0 Attachment
                      * pansz <panshizhu@...> [2009-11-05 15:05 +0800]:
                      > bill lam 写道:
                      > > On Sun, 01 Nov 2009, James Michael Fultz wrote:
                      > >> # ~/.profile, ~/.bashrc, ~/.zshenv, etc.
                      > >> EDITOR=vim
                      > >> VISUAL=$EDITOR
                      > >> export EDITOR VISUAL
                      > >>
                      > >> and:
                      > >>
                      > >> $ sudoedit file
                      > >
                      > > or
                      > >
                      > > $ sudo -e file
                      > >
                      >
                      > sudoedit type 1 more key than sudo vi
                      >
                      > sudo -e needs the same number of keystrokes, but sudo vi is easier to
                      > remember.
                      >
                      > So why do you think sudo -e or sudo edit is better than sudo vi ?

                      The latter does not preserve your personal Vim environment.

                      See sudo(8):

                      -e The -e (edit) option indicates that, instead of running a command,
                      the user wishes to edit one or more files. In lieu of a command,
                      the string "sudoedit" is used when consulting the sudoers file. If
                      the user is authorized by sudoers the following steps are taken:

                      1. Temporary copies are made of the files to be edited with the
                      owner set to the invoking user.

                      2. The editor specified by the VISUAL or EDITOR environment vari‐
                      ables is run to edit the temporary files. If neither VISUAL
                      nor EDITOR are set, the program listed in the editor sudoers
                      variable is used.

                      3. If they have been modified, the temporary files are copied back
                      to their original location and the temporary versions are
                      removed.

                      If the specified file does not exist, it will be created. Note
                      that unlike most commands run by sudo, the editor is run with the
                      invoking user’s environment unmodified. If, for some reason, sudo
                      is unable to update a file with its edited version, the user will
                      receive a warning and the edited copy will remain in a temporary
                      file.

                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • pansz
                      ... oops, got it. I setup my sudo to always preserve my personal environment for all commands, so I do never need the sudo -e.
                      Message 10 of 12 , Nov 8, 2009
                      • 0 Attachment
                        James Michael Fultz 写道:
                        >>
                        >> So why do you think sudo -e or sudo edit is better than sudo vi ?
                        >
                        > The latter does not preserve your personal Vim environment.
                        >
                        oops, got it.

                        I setup my sudo to always preserve my personal environment for all
                        commands, so I do never need the sudo -e.


                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • Matt Wozniski
                        ... It s also horrifically dangerous to use sudo vim when sudoedit would do. sudo vim means that vim runs as root, so a malicious script, or a vim bug,
                        Message 11 of 12 , Nov 10, 2009
                        • 0 Attachment
                          On Sun, Nov 8, 2009 at 8:17 PM, pansz wrote:
                          >
                          >
                          > James Michael Fultz 写道:
                          >>>
                          >>> So why do you think sudo -e or sudo edit is better than sudo vi ?
                          >>
                          >> The latter does not preserve your personal Vim environment.
                          >>
                          > oops, got it.
                          >
                          > I setup my sudo to always preserve my personal environment for all
                          > commands, so I do never need the sudo -e.

                          It's also horrifically dangerous to use "sudo vim" when "sudoedit"
                          would do. "sudo vim" means that vim runs as root, so a malicious
                          script, or a vim bug, could have catastrophic consequences.
                          "sudoedit" runs vim as your user, so malicious scripts or catastrophic
                          bugs can't result in an "rm -rf /" or worse being run.

                          If you don't absolutely *need* to run vim as root, I'd recommend
                          against it. And, if you *do* need to run vim as root, I'd recommend
                          disabling all plugins, colorschemes, syntax highlighting, etc. But
                          that's just my $0.02 - people less concerned with running an editor
                          with a history of exploitable bugs as root are of course welcome to do
                          so.

                          ~Matt

                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_use" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        • pansz
                          ... It convince me. So the difference is: sudo -e copies the file in tmp and edit as user, while sudo vi edit the file as root. Hope more user know it.
                          Message 12 of 12 , Nov 10, 2009
                          • 0 Attachment
                            Matt Wozniski 写道:
                            > On Sun, Nov 8, 2009 at 8:17 PM, pansz wrote:
                            >> James Michael Fultz 写道:
                            >>>> So why do you think sudo -e or sudo edit is better than sudo vi ?
                            >>>
                            >>> The latter does not preserve your personal Vim environment.
                            >>>
                            >> oops, got it.
                            >>
                            >> I setup my sudo to always preserve my personal environment for all
                            >> commands, so I do never need the sudo -e.
                            >
                            > It's also horrifically dangerous to use "sudo vim" when "sudoedit"
                            > would do. "sudo vim" means that vim runs as root, so a malicious
                            > script, or a vim bug, could have catastrophic consequences.
                            > "sudoedit" runs vim as your user, so malicious scripts or catastrophic
                            > bugs can't result in an "rm -rf /" or worse being run.

                            It convince me.

                            So the difference is: sudo -e copies the file in tmp and edit as user,
                            while sudo vi edit the file as root.

                            Hope more user know it.


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