As system administrator I have to work under several user IDs, some of which are shared with others. We all have different tastes in what we like in terms of settings for our vi, so I am looking at ways to easily set up our own preferences. It would be ideal to use the -u option:

vi -u ~myusername/.vimrc

However, it looks like it simply gets ignored - I have tried to strace it, and there is no reference to the alternative vimrc at all. Is there some other option I need to use?

---EDIT--- To answer the questions in the comments:

bash-4.2$ type -a vi
vi is /bin/vi
vi is /usr/bin/vi

The version:

bash-4.2$ vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  2 2017 00:45:54)
Included patches: 1-160
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):
+acl             -farsi           -mouse_sgr       -tag_old_static
-arabic          -file_in_path    -mouse_sysmouse  -tag_any_white
-autocmd         -find_in_path    -mouse_urxvt     -tcl
-balloon_eval    -float           -mouse_xterm     +terminfo
-browse          -folding         +multi_byte      -termresponse
+builtin_terms   -footer          -multi_lang      -textobjects
-byte_offset     +fork()          -mzscheme        -title
-cindent         -gettext         -netbeans_intg   -toolbar
-clientserver    -hangul_input    -path_extra      -user_commands
-clipboard       +iconv           -perl            -vertsplit
-cmdline_compl   -insert_expand   -persistent_undo -virtualedit
+cmdline_hist    +jumplist        -printer         +visual
-cmdline_info    -keymap          -profile         -visualextra
-comments        -langmap         -python          -viminfo
-conceal         -libcall         -python3         -vreplace
-cryptv          -linebreak       -quickfix        +wildignore
-cscope          -lispindent      -reltime         -wildmenu
-cursorbind      -listcmds        -rightleft       +windows
-cursorshape     -localmap        -ruby            +writebackup
-dialog          -lua             -scrollbind      -X11
-diff            -menu            -signs           -xfontset
-digraphs        -mksession       -smartindent     -xim
-dnd             -modify_fname    -sniff           -xsmp
-ebcdic          -mouse           -startuptime     -xterm_clipboard
-emacs_tags      -mouse_dec       -statusline      -xterm_save
-eval            -mouse_gpm       -sun_workshop    -xpm
-ex_extra        -mouse_jsbterm   -syntax          
-extra_search    -mouse_netterm   -tag_binary      
   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-z,relro  -L/usr/local/lib -Wl,--as-needed -o vim        -lm  -lselinux -lncurses -lacl -lattr -ldl          

The odd - very odd IMO - thing is, when I expand the path of ~myusername/.vimrc using echo ~myusername/.vimrc (IOW using the shell as normal) and then start vi -u with the explicit path, then it works, which makes no sense to me.

  • vi or vim? Are you sure "vi" isn't aliased or anything like that? What does type -a vi return? – B Layer Feb 8 '19 at 11:45
  • I don't see any reason for your problem. What's the output of vi --version? – Ralf Feb 8 '19 at 11:48
  • If this is actually Vim, check the :scriptnames output. Also, are you sure, your shell expanded ~myusername correctly? Does it work if you expand the path completely? I suppose you already checked permissions? – Christian Brabandt Feb 8 '19 at 13:05
  • 1
    If you do set -x; vim -u ~myusername/.vimrc; set +x, you should see what the filename is expanded to. – Ralf Feb 8 '19 at 14:08
  • As a system administrator, wouldn't it be safer to do this using su so that the user's .vimrc is not executed with root permissions? I mean, I just use USERNAME=myusername, because I use zsh and I find su's command line parsing to be annoying, but it feels to me like it'd be better to not parse an untrusted .vimrc as root. Maybe it's just showing my age and remembering that doing that with .exrc was a bad thing... Or do you really mean your .vimrc, and this is just to work around the fact you haven't set your HOME when root as your HOME directory? – Ed Grimm Feb 9 '19 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.