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

Comments:

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

Posted by Darren Moffat on November 10, 2012 at 08:16 AM PST #

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? :-)

Posted by guest on November 13, 2012 at 10:57 AM PST #

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.

Posted by Tim Cook on November 13, 2012 at 02:04 PM PST #

Post a Comment:
Comments are closed for this entry.
About

Tim Cook's Weblog The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today