My question is a spinoff from this previous question 6 months ago, so to get more details and see how I've installed Vim Plug have a look here.
Currently I wanted to add this extension.
https://github.com/mattn/emmet-vim
Here's my .vimrc
file.
1
2 syntax on
3 map <F5> :source ~/.vimrc<CR>
4
5 set background=light " set background = set bg
6
7 " colorscheme desert
8 colorscheme elflord
9 " colorscheme slate
10 " colorscheme pablo
11 " colorscheme koehler
12 " colorscheme murphy
13 " colorscheme industry
14 " colorscheme torte
15 " colorscheme default
16 " colorscheme morning
17 " colorscheme ron
18 "
19 set background=dark " Setting up background=dark, makes text lighter
20 "
21 "
22 "
23 set nocompatible " Set compatibility to Vim only
24 set wildmenu " Enable Vim's builtin auto completion engine
25 set ignorecase " By default searching in Vin using / command is case-sensitive.
26 " Use 'set ignorecase' to set searching in Vim case insensitive.
27 " Use 'set smartcase' to make search case insensitive if you type the search pattern using lower case only.
28 "
29 set number " Show line numbers. Opposite is set nonumber.
30 "
31 set shiftwidth=3 " Set tabulator size to 4
32 set tabstop=3 " Set tabulator size to 4
33 set softtabstop=3 " Set tabulator size to 4
34 "
35 set wrap " Automatically wrap text that extends beyond the screen length
36 "
37 set laststatus=2 " Show status bar
38 "
39 set encoding=utf-8 " Force encoding
40 set list " Shows hidden characters
41 set nolist " Hide invisible characters
42 "
43 "
44 "
45 " Call the .vimrc.plug file
46 if filereadable(expand("~/.vimrc.plug"))
47 source /home/michal/.vimrc.plug
48 endif
49
And here's my .vimrc.plug
file:
1 " Plugins will be downloaded under the specified directory.
2 call plug#begin('~/.vim/plugged')
3
4 " Fugitive Vim Github Wrapper
5 Plug 'tpope/vim-fugitive'
6 " Emmet Vim
7 Plug 'mattn/emmet-vim'
8
9 call plug#end()
Both of these files are located in my user directory /home/michal/
, like so:
michal@ubuntu:~$ ls -lah /home/michal/.vim*
-rw------- 1 michal michal 20K Jun 21 23:23 /home/michal/.viminfo
-rw-rw-r-- 1 michal michal 1.7K Jun 21 23:12 /home/michal/.vimrc
-rw-rw-r-- 1 michal michal 203 Jun 21 23:09 /home/michal/.vimrc.plug
-rw-rw-r-- 1 michal michal 110 Dec 14 2022 /home/michal/.vimrc.plug.bak
-rw-r--r-- 1 root root 12K Jun 21 23:53 /home/michal/.vimrc.plug.swp
When I execute the command :PlugInstall
while I run Vim as michal
user, everything works fine.
But when I open Vim using sudo vim
and then try to run :PlugInstall
, I get E492: Not an editor command: PlugInstall
error.
Why is that?
I'm using Vim 95/100 times using sudo vim filename
, therefore I need all those plugins I install with Vim Plug, to work in sudo mode.
$HOME
to that of the target user (in this case,root
), so that's wheresudo vim
looks for its config files. See for example How do Ubuntu and Debian manage $HOME for users with sudo privileges?