X

How to Get Vim to do Filename Completion Even When You are Root

From the Obscure Unix Admin Tip of the Day section...

If you occasionally edit files as root (I never do, I always use pfexec, wink wink), then you may have noticed that the vim (Vi Improved) editor that normally does filename completion via the <Tab> key now gives you something like:

:e /etc/mo^I

when you try to open up /etc/motd with a little less typing

So, there are at least five solutions to this:

  • Use <Ctrl>-E instead of <Tab>
  • Use the "-N" flag when you start Vim
  • :set wildchar=<Tab> (Enter those 5 characters, not an actual Tab)
  • Use pfexec vim filename
  • In Solaris 11.1 or later, use pfedit filename

The reason for this? It seems that when you are root, Vim sets it's "compatible" flag, which makes it behave more like its ancestor vi. In turn this makes Vim set 'wildchar' to <Ctrl>-E.

For more info, read the section you get when you enter :help cmdline-completion


Thanks to Darren for the tip on pfexec

Join the discussion

Comments ( 3 )
  • Darren Moffat Saturday, November 10, 2012

    In Solaris 11.1 there is another solution, just use pfedit(1M) then the editor runs as you, no need to pfexec(1) either.


  • guest Tuesday, November 13, 2012

    With ksh under Solaris (and other SVR4 OS's) - when the EDITOR variable is exported to one of the vi's (vi, xpg4/bin/vi, or xpg6/bin/vi), the file name completion is an <esc><*>

    I would have expected this to be more like the "ancestor" - <cntrl><E> seems bizarre.

    Does anyone use bourne shell as the root shell any longer? :-)


  • Tim Cook Tuesday, November 13, 2012

    It made me wonder whether <Ctrl>-E might have come from "nvi" which was a more "legit" descendant of vi - it came from a project to replace license-encumbered parts of BSD with FOSS-licensed equivalents.

    In any case, I want my vi-like editor to behave like my shell (and most shells) for filename completion.

    I would think the answer to your question is approximately no - nobody uses the Bourne shell for anything other than scripts any more. Even Solaris has caught up on modern times and anointed Bash as the interactive shell for root.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services